ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Senthilmurugan, ANGLER - EIT" <senthilmuru...@angleritech.com>
Subject RE: insert using a stored procedure
Date Wed, 22 Nov 2006 09:14:35 GMT
<!-Oracle SEQUENCE Example using .NET 1.1 System.Data.OracleClient --> 
<insert id="insertProduct-ORACLE" parameterClass="product"> 
  <selectKey resultClass="int" type="pre" property="Id" > 
     SELECT STOCKIDSEQUENCE.NEXTVAL AS VALUE 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="product"> 
  insert into PRODUCT (PRD_DESCRIPTION)
  values (#description#) 
 <selectKey resultClass="int" type="post" property="id" > 
   select @@IDENTITY as value
 </selectKey>
</insert>

<!-- MySQL Example -->
<insert id="insertProduct-MYSQL" parameterClass="product"> 
  insert into PRODUCT (PRD_DESCRIPTION)
  values (#description#) 
 <selectKey resultClass="int" type="post" property="id" > 
   select LAST_INSERT_ID() as value
 </selectKey>
</insert>

________________________________

From: Dorin Manoli [mailto:Dorin.Manoli@dataireland.ie] 
Sent: Wednesday, November 22, 2006 2:19 PM
To: user-cs@ibatis.apache.org
Subject: RE: insert using a stored procedure



It depend what database engine you use. Code below is for MySQL

Use this code in xml map file under <insert> node and after insert query

<selectKey .... . . . >

                        select LAST_INSERT_ID() as value          

                  </selectKey>

 

________________________________

From: Bob Hanson [mailto:mnbob70@gmail.com] 
Sent: Tuesday, November 21, 2006 6:49 PM
To: user-cs@ibatis.apache.org
Subject: insert using a stored procedure

 

What is the correct method to retrieve the Identity value of a newly
inserted row when using a stored procedure that performs an insert?

Thanks,
Bob


Mime
View raw message