You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by John Chien <jo...@ncmail.net> on 2005/12/13 14:56:09 UTC

the return result of insert, update, and delete in SqlMapClient API

The SqlMapClient API indicates:

public int insert(String statementName, Object parameterObject) throws 
SQLException.
public int update(String statementName, Object parameterObject) throws 
SQLException
public int delete(String statementName, Object parameterObject) throws 
SQLException

what does the return int repesent ?

the example shows

int rows = sqlMap.insert("insertProduct", product);

Does the return int represent the number of rows being inserted, updated 
or deleted ?

Is there anyway of returning the Object or the List of the rows being 
inserted, updated or deleted ?


Thanks,

John Chien

autogenerated key in insertion

Posted by John Chien <jo...@ncmail.net>.
Dear Sir:

In the IBatis Data Mapper Developer Guide page 9,
there is an example of using Auto-Generated Keys to do the insertion.
The insertion uses <selectKey> tag.

However, the document was not properly formatted.
Thus, the example can not be seen.

Does anybody know what the example should look like ?


Thanks,

John Chien

Re: the return result of insert, update, and delete in SqlMapClient API

Posted by Larry Meadors <lm...@apache.org>.
The Dev guide is wrong.

It returns the results of selectKey...

Larry


On 12/13/05, Meindert <me...@pastelebusiness.com> wrote:
>
>
>
> >Uhm, insert() does not return an int.
> According to the Developer Guide (page 43) it does.
> The javadoc say's that it returns a java.lang.Object containing the primary
> key, the primary key field is defined with the <selectKey> tag in the Sql.
>
> Meindert
>
> >Larry
>
>
> On 12/13/05, Leonardo Kenji Shikida <sh...@gmail.com> wrote:
> > I believe it means the number of affected rows (just like jdbc)
> >
> > On 12/13/05, John Chien <jo...@ncmail.net> wrote:
> > > The SqlMapClient API indicates:
> > >
> > > public int insert(String statementName, Object parameterObject) throws
> > > SQLException.
> > > public int update(String statementName, Object parameterObject) throws
> > > SQLException
> > > public int delete(String statementName, Object parameterObject) throws
> > > SQLException
> > >
> > > what does the return int repesent ?
> > >
> > > the example shows
> > >
> > > int rows = sqlMap.insert("insertProduct", product);
> > >
> > > Does the return int represent the number of rows being inserted, updated
> > > or deleted ?
> > >
> > > Is there anyway of returning the Object or the List of the rows being
> > > inserted, updated or deleted ?
> > >
> > >
> > > Thanks,
> > >
> > > John Chien
> > >
> > >
> > >
> >
> >
> > --
> >
> > []
> >
> > Kenji
> > _______________________
> > http://kenjiria.blogspot.com
> > http://gaitabh.blogspot.com
> >
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005
>
>
>

Re: the return result of insert, update, and delete in SqlMapClient API

Posted by John Chien <jo...@ncmail.net>.
Meindert:

Thank you.
I do not use mysql. I use Oracle.
However, the statement is very similar.
Due to my parameter class is a little complicated, the insertion is a 
little complicated too.
After numerous tries, I got it done finally.

Suppose you have a parameter class called DataBean.
The DataBean is like:

public DataBean {  // No method is described here
   private IdBean idBean;
   private String column1;
   private int column2;
}

The IdBean is like

public IdBean { // No Method is described here
    private String    id;
    private int         otherField;
}

The table A has three columns:
      A_ID, A_COLUMN1, A_COLUMN2

The insert statement can be

<insert id="insertA" parameterClass="DataBean">
/   <selectKey keyProperty="idBean.id" 
resultClass="java.lang.String">      <!-- the resultClass  must be the 
same type as the id field in the parameter class -->/

/        SELECT SEQ_A.NEXTVAL AS id FROM 
DUAL                                    <!-- the  keyProperty must be  
according to the   idBean structure                          -->/

/   </selectKey>/

   /INSERT INTO A (//A_ID, A_column1, A_column2//)/

/      VALUES (#dataBean.id#, //#dataBean.column1#, #dataBean.column2#)
</insert>
/



Meindert wrote:

>Hi John Chien,
>
> 
>
> Sorry but are not to sure about what you mean with the sequence stuff.
>
>  
>
> I’m using the selectKey tag to return to me the automatic key 
> generated by the database,
>
> So for table A with columns id (=auto number), column1, column2 I 
> would just insert data for the column1 and column2 and let <selectKey> 
> return me the value in the generated id column, here is a example that 
> works for mysql and mssql:
>
>  
>
> /<insert id="insertA" parameterClass="//DataBean//">/
>
> /    INSERT INTO A (//column1, column2//)/
>
> /      VALUES (//#column1#, #column2#)///
>
> /      <selectKey keyProperty="id" resultClass="int">/
>
> /        SELECT @@IDENTITY AS ID/
>
> /      </selectKey>/
>
> /  </insert>/
>
>  
>
> *MEINDERT HOVING*
>
> *From:* John Chien [mailto:john.chien@ncmail.net]
> *Sent:* 13 December 2005 05:21 PM
> *To:* user-java@ibatis.apache.org
> *Cc:* lmeadors@apache.org
> *Subject:* Re: the return result of insert, update, and delete in 
> SqlMapClient API
>
>  
>
>Meindert:
>
> 
>
>Thanks. I could not see the javadoc now.
>
>The iBatis.apache.org is down currently.
>
> 
>
>How can I use the <selectKey> tag ?
>
>Do you have an example ? 
>
> 
>
>Suppose the table is A, and its primary key is id. The sequence of table A is seq_A.
>
>The bean that conatains the data to be inserted is called DataBean which
>
>properties are id, column1, column2.
>
> 
>
>Can I specify the statement as:
>
> 
>
> 
>
><statement id="insertA" parameterClass="DataBean" resultClass="Integer">
>
> 
>
>    <selectKey property="id" type="pre" resultClass="int">
>
> 
>
>        select seq_A.nextval as value from dual
>
> 
>
>    </selectKey>            
>
> 
>
>    INSERT INTO A
>
> 
>
>        (id, column1, column2) 
>
>    VALUES
>
> 
>
>        (#id#, #column1#, #column2#)
>
> 
>
></statement>
>
> 
>
> 
>
>Thanks,
>
> 
>
> 
>
>
>
> Meindert wrote:
>
> 
>
> 
>
>  
>
>>Uhm, insert() does not return an int.
>>
>>    
>>
>According to the Developer Guide (page 43) it does.
>
>The javadoc say's that it returns a java.lang.Object containing the primary
>
>key, the primary key field is defined with the <selectKey> tag in the Sql.
>
> 
>
>Meindert
>
> 
>
>  
>
>>Larry
>>
>>    
>>
> 
>
> 
>
>On 12/13/05, Leonardo Kenji Shikida <sh...@gmail.com> <ma...@gmail.com> wrote:
>
>  
>
>>I believe it means the number of affected rows (just like jdbc)
>>
>> 
>>
>>On 12/13/05, John Chien <jo...@ncmail.net> <ma...@ncmail.net> wrote:
>>
>>    
>>
>>>The SqlMapClient API indicates:
>>>
>>> 
>>>
>>>public int insert(String statementName, Object parameterObject) throws
>>>
>>>SQLException.
>>>
>>>public int update(String statementName, Object parameterObject) throws
>>>
>>>SQLException
>>>
>>>public int delete(String statementName, Object parameterObject) throws
>>>
>>>SQLException
>>>
>>> 
>>>
>>>what does the return int repesent ?
>>>
>>> 
>>>
>>>the example shows
>>>
>>> 
>>>
>>>int rows = sqlMap.insert("insertProduct", product);
>>>
>>> 
>>>
>>>Does the return int represent the number of rows being inserted, updated
>>>
>>>or deleted ?
>>>
>>> 
>>>
>>>Is there anyway of returning the Object or the List of the rows being
>>>
>>>inserted, updated or deleted ?
>>>
>>> 
>>>
>>> 
>>>
>>>Thanks,
>>>
>>> 
>>>
>>>John Chien
>>>
>>> 
>>>
>>> 
>>>
>>> 
>>>
>>>      
>>>
>> 
>>
>>--
>>
>> 
>>
>>[]
>>
>> 
>>
>>Kenji
>>
>>_______________________
>>
>>http://kenjiria.blogspot.com
>>
>>http://gaitabh.blogspot.com
>>
>> 
>>
>>    
>>
> 
>
>  
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 
> 08/12/2005
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 
> 08/12/2005
>

RE: the return result of insert, update, and delete in SqlMapClient API

Posted by Meindert <me...@pastelebusiness.com>.
Hi John Chien,
 

Sorry but are not to sure about what you mean with the sequence stuff.

 

I’m using the selectKey tag to return to me the automatic key generated by
the database,

So for table A with columns id (=auto number), column1, column2 I would just
insert data for the column1 and column2 and let <selectKey> return me the
value in the generated id column, here is a example that works for mysql and
mssql:

 

<insert id="insertA" parameterClass="DataBean">

    INSERT INTO A (column1, column2)

      VALUES (#column1#, #column2#)

      <selectKey keyProperty="id" resultClass="int">

        SELECT @@IDENTITY AS ID

      </selectKey>

  </insert>

 

MEINDERT HOVING



From: John Chien [mailto:john.chien@ncmail.net] 
Sent: 13 December 2005 05:21 PM
To: user-java@ibatis.apache.org
Cc: lmeadors@apache.org
Subject: Re: the return result of insert, update, and delete in SqlMapClient
API

 

Meindert:
 
Thanks. I could not see the javadoc now.
The iBatis.apache.org is down currently.
 
How can I use the <selectKey> tag ?
Do you have an example ? 
 
Suppose the table is A, and its primary key is id. The sequence of table A
is seq_A.
The bean that conatains the data to be inserted is called DataBean which
properties are id, column1, column2.
 
Can I specify the statement as:
 
 
<statement id="insertA" parameterClass="DataBean" resultClass="Integer">
 
    <selectKey property="id" type="pre" resultClass="int">
 
        select seq_A.nextval as value from dual
 
    </selectKey>            
 
    INSERT INTO A
 
        (id, column1, column2) 
    VALUES
 
        (#id#, #column1#, #column2#)
 
</statement>
 
 
Thanks,
 
 



Meindert wrote: 

 
 
  

Uhm, insert() does not return an int.
    

According to the Developer Guide (page 43) it does.
The javadoc say's that it returns a java.lang.Object containing the primary
key, the primary key field is defined with the <selectKey> tag in the Sql.
 
Meindert
 
  

Larry
    

 
 
On 12/13/05, Leonardo Kenji Shikida HYPERLINK
"mailto:shikida@gmail.com"<sh...@gmail.com> wrote:
  

I believe it means the number of affected rows (just like jdbc)
 
On 12/13/05, John Chien HYPERLINK
"mailto:john.chien@ncmail.net"<jo...@ncmail.net> wrote:
    

The SqlMapClient API indicates:
 
public int insert(String statementName, Object parameterObject) throws
SQLException.
public int update(String statementName, Object parameterObject) throws
SQLException
public int delete(String statementName, Object parameterObject) throws
SQLException
 
what does the return int repesent ?
 
the example shows
 
int rows = sqlMap.insert("insertProduct", product);
 
Does the return int represent the number of rows being inserted, updated
or deleted ?
 
Is there anyway of returning the Object or the List of the rows being
inserted, updated or deleted ?
 
 
Thanks,
 
John Chien
 
 
 
      

 
--
 
[]
 
Kenji
_______________________
HYPERLINK "http://kenjiria.blogspot.com"http://kenjiria.blogspot.com
HYPERLINK "http://gaitabh.blogspot.com"http://gaitabh.blogspot.com
 
    

 
  


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005
 

Re: the return result of insert, update, and delete in SqlMapClient API

Posted by John Chien <jo...@ncmail.net>.
Meindert:

Thanks. I could not see the javadoc now.
The iBatis.apache.org is down currently.

How can I use the <selectKey> tag ?
Do you have an example ? 

Suppose the table is A, and its primary key is id. The sequence of table A is seq_A.
The bean that conatains the data to be inserted is called DataBean which
properties are id, column1, column2.

Can I specify the statement as:


<statement id="insertA" parameterClass="DataBean" resultClass="Integer">

    <selectKey property="id" type="pre" resultClass="int">

        select seq_A.nextval as value from dual

    </selectKey>            

    INSERT INTO A

        (id, column1, column2) 
    VALUES

        (#id#, #column1#, #column2#)

</statement>


Thanks,





Meindert wrote:

>
>  
>
>>Uhm, insert() does not return an int.
>>    
>>
>According to the Developer Guide (page 43) it does.
>The javadoc say's that it returns a java.lang.Object containing the primary
>key, the primary key field is defined with the <selectKey> tag in the Sql.
>
>Meindert
>
>  
>
>>Larry
>>    
>>
>
>
>On 12/13/05, Leonardo Kenji Shikida <sh...@gmail.com> wrote:
>  
>
>>I believe it means the number of affected rows (just like jdbc)
>>
>>On 12/13/05, John Chien <jo...@ncmail.net> wrote:
>>    
>>
>>>The SqlMapClient API indicates:
>>>
>>>public int insert(String statementName, Object parameterObject) throws
>>>SQLException.
>>>public int update(String statementName, Object parameterObject) throws
>>>SQLException
>>>public int delete(String statementName, Object parameterObject) throws
>>>SQLException
>>>
>>>what does the return int repesent ?
>>>
>>>the example shows
>>>
>>>int rows = sqlMap.insert("insertProduct", product);
>>>
>>>Does the return int represent the number of rows being inserted, updated
>>>or deleted ?
>>>
>>>Is there anyway of returning the Object or the List of the rows being
>>>inserted, updated or deleted ?
>>>
>>>
>>>Thanks,
>>>
>>>John Chien
>>>
>>>
>>>
>>>      
>>>
>>--
>>
>>[]
>>
>>Kenji
>>_______________________
>>http://kenjiria.blogspot.com
>>http://gaitabh.blogspot.com
>>
>>    
>>
>
>  
>

RE: the return result of insert, update, and delete in SqlMapClient API

Posted by Meindert <me...@pastelebusiness.com>.


>Uhm, insert() does not return an int.
According to the Developer Guide (page 43) it does.
The javadoc say's that it returns a java.lang.Object containing the primary
key, the primary key field is defined with the <selectKey> tag in the Sql.

Meindert

>Larry


On 12/13/05, Leonardo Kenji Shikida <sh...@gmail.com> wrote:
> I believe it means the number of affected rows (just like jdbc)
>
> On 12/13/05, John Chien <jo...@ncmail.net> wrote:
> > The SqlMapClient API indicates:
> >
> > public int insert(String statementName, Object parameterObject) throws
> > SQLException.
> > public int update(String statementName, Object parameterObject) throws
> > SQLException
> > public int delete(String statementName, Object parameterObject) throws
> > SQLException
> >
> > what does the return int repesent ?
> >
> > the example shows
> >
> > int rows = sqlMap.insert("insertProduct", product);
> >
> > Does the return int represent the number of rows being inserted, updated
> > or deleted ?
> >
> > Is there anyway of returning the Object or the List of the rows being
> > inserted, updated or deleted ?
> >
> >
> > Thanks,
> >
> > John Chien
> >
> >
> >
>
>
> --
>
> []
>
> Kenji
> _______________________
> http://kenjiria.blogspot.com
> http://gaitabh.blogspot.com
>

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/195 - Release Date: 08/12/2005
 


Re: the return result of insert, update, and delete in SqlMapClient API

Posted by Larry Meadors <lm...@apache.org>.
Uhm, insert() does not return an int.

Larry


On 12/13/05, Leonardo Kenji Shikida <sh...@gmail.com> wrote:
> I believe it means the number of affected rows (just like jdbc)
>
> On 12/13/05, John Chien <jo...@ncmail.net> wrote:
> > The SqlMapClient API indicates:
> >
> > public int insert(String statementName, Object parameterObject) throws
> > SQLException.
> > public int update(String statementName, Object parameterObject) throws
> > SQLException
> > public int delete(String statementName, Object parameterObject) throws
> > SQLException
> >
> > what does the return int repesent ?
> >
> > the example shows
> >
> > int rows = sqlMap.insert("insertProduct", product);
> >
> > Does the return int represent the number of rows being inserted, updated
> > or deleted ?
> >
> > Is there anyway of returning the Object or the List of the rows being
> > inserted, updated or deleted ?
> >
> >
> > Thanks,
> >
> > John Chien
> >
> >
> >
>
>
> --
>
> []
>
> Kenji
> _______________________
> http://kenjiria.blogspot.com
> http://gaitabh.blogspot.com
>

Re: the return result of insert, update, and delete in SqlMapClient API

Posted by Leonardo Kenji Shikida <sh...@gmail.com>.
I believe it means the number of affected rows (just like jdbc)

On 12/13/05, John Chien <jo...@ncmail.net> wrote:
> The SqlMapClient API indicates:
>
> public int insert(String statementName, Object parameterObject) throws
> SQLException.
> public int update(String statementName, Object parameterObject) throws
> SQLException
> public int delete(String statementName, Object parameterObject) throws
> SQLException
>
> what does the return int repesent ?
>
> the example shows
>
> int rows = sqlMap.insert("insertProduct", product);
>
> Does the return int represent the number of rows being inserted, updated
> or deleted ?
>
> Is there anyway of returning the Object or the List of the rows being
> inserted, updated or deleted ?
>
>
> Thanks,
>
> John Chien
>
>
>


--

[]

Kenji
_______________________
http://kenjiria.blogspot.com
http://gaitabh.blogspot.com