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:
get id with iBatis (Statement.RETURN_GENERATED_KEYS)
Sent from the
iBATIS - User - Java forum at Nabble.com.