How to get the return value using insert in Ibatis and MySQL environments

Source: Internet
Author: User

    1. The SQL statement in the configuration XML file, the INSERT statement has a return value by default, to mark whether the insertion was successful. If additional return values are required, further setup is required.

Take the following code as an example:

1     <InsertID= "Insertandgetid"Parameterclass= "Vnet_stack" >  2 Insert into3 Vnet_stack (stack_name)4 values (#stack_name #)5         <SelectkeyResultClass= "int"Keyproperty= "stack_id" >6 SELECT last_insert_id ()7         </Selectkey>8         9     </Insert>

Where the return value type ResultClass is set to the integer type, Keyproperty sets the data source.

After that, a simple nested query statement can be used to query to the newly added newest row, and take the entry of Keyproperty set as the return value

2. Adding functions in the DAO layer

  

1     @Override 2      Public int Insertandgetid (Vnet_stack ss) {3         // TODO auto-generated Method Stub 4         return Integer.parseint (String.valueof (Getsqlmapclienttemplate (). Insert ("Vnet_stack.insertandgetid", ss)); 5         6     }

The function is then called to get the required primary key ID as the return value.

How to get the return value using insert in Ibatis and MySQL environments

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.