ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xianwinwin <xianwin...@gmail.com>
Subject get id with iBatis (Statement.RETURN_GENERATED_KEYS)
Date Tue, 16 May 2006 17:24:40 GMT

Hi guys

I am new to iBatis.

My question is very simple, in the old days I used to write a statement such
as the one below to get the  the GENERATED_KEYS. in other words, this
statement return the id of the new recod.

                Statement stmt1 = con.createStatement();
                stmt1.executeUpdate(query1,
Statement.RETURN_GENERATED_KEYS); 
                ResultSet rs = stmt1.getGeneratedKeys();
              
                long id=-1;
                while (rs.next()) 
                {
                	id = rs.getLong(1);                
                }

 
How can this be done using iBatis? I mean my xml file looks like this:


    INSERT INTO employee 
   (First_Name, Last_Name, Branch) 
   VALUES
   (#firstName#,#lastName#,#branch#) 
  


and the call is:

try{
					
ibatis.getSqlMap().executeUpdate("addNewTravelAgentFromProductionFile",ta);
						travelAgentList.add(ta);
						
					}catch(SQLException e)
					{
						//travel agent already exist in db
					}

Please feel free to criticize my code if you feel I’m doing something
inefficient/wrong

thanks
xww

--
View this message in context: http://www.nabble.com/get-id-with-iBatis-%28Statement.RETURN_GENERATED_KEYS%29-t1629789.html#a4414682
Sent from the iBATIS - User - Java forum at Nabble.com.

Mime
View raw message