ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: get id with iBatis (Statement.RETURN_GENERATED_KEYS)
Date Tue, 16 May 2006 17:43:05 GMT
Take a look at <selectKey> in the iBATIS documentation.

Jeff Butler



On 5/16/06, xianwinwin <xianwinwin@gmail.com> wrote:
>
> 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)<http://www.nabble.com/get-id-with-iBatis-%28Statement.RETURN_GENERATED_KEYS%29-t1629789.html#a4414682>
> Sent from the iBATIS - User - Java<http://www.nabble.com/iBATIS---User---Java-f370.html>forum
at
> Nabble.com <http://nabble.com/>.
>
>

Mime
View raw message