Hi, I’m beginner with iBatis and want to know how to insert into MySQL database  table a row which primary key is ‘Auto_Increment’   type and I want to be returned the id of my table like in this examples from “iBATIS Developer Guide”.

 

 

<!—Oracle SEQUENCE Example -->

<insert id="insertProduct-ORACLE" parameterClass="com.domain.Product">

<selectKey resultClass="int" >

SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL

</selectKey>

insert into PRODUCT (PRD_ID,PRD_DESCRIPTION)

values (#id#,#description#)

</insert>

<!— Microsoft SQL Server IDENTITY Column Example -->

<insert id="insertProduct-MS-SQL" parameterClass="com.domain.Product">

insert into PRODUCT (PRD_DESCRIPTION)

values (#description#)

<selectKey resultClass="int" >

SELECT @@IDENTITY AS ID

</selectKey>

</insert>


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.

Reply via email to