Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 20106 invoked from network); 16 May 2006 17:43:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 May 2006 17:43:29 -0000 Received: (qmail 24023 invoked by uid 500); 16 May 2006 17:43:27 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 23997 invoked by uid 500); 16 May 2006 17:43:27 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 23976 invoked by uid 99); 16 May 2006 17:43:26 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 May 2006 10:43:26 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of jeffgbutler@gmail.com designates 66.249.82.197 as permitted sender) Received: from [66.249.82.197] (HELO wx-out-0102.google.com) (66.249.82.197) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 May 2006 10:43:26 -0700 Received: by wx-out-0102.google.com with SMTP id s11so22039wxc for ; Tue, 16 May 2006 10:43:05 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=YM7pJYdcuKm3p0reO5pVDcT7OvrTI07K2UXjoCs0BrkQsl+88mwvie3n+NjL//opzGabVJGajghRI3LHf6ciNHUYRBJRpeeqdjPjKH4k+eaErdmOVbf73WMLZGndQKG4NJ+HDyqkPNveQnwc7RQSK8YQ1ibtw23I8dSoJ8zeu1c= Received: by 10.70.33.19 with SMTP id g19mr11729wxg; Tue, 16 May 2006 10:43:05 -0700 (PDT) Received: by 10.70.72.14 with HTTP; Tue, 16 May 2006 10:43:05 -0700 (PDT) Message-ID: Date: Tue, 16 May 2006 12:43:05 -0500 From: "Jeff Butler" To: user-java@ibatis.apache.org Subject: Re: get id with iBatis (Statement.RETURN_GENERATED_KEYS) In-Reply-To: <4414682.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12391_20619999.1147801385451" References: <4414682.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_12391_20619999.1147801385451 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Take a look at in the iBATIS documentation. Jeff Butler On 5/16/06, xianwinwin 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 =3D con.createStatement(); stmt1.executeUpdate(que= ry1, > Statement.RETURN_GENERATED_KEYS); ResultSet rs =3D stmt1.getGeneratedKeys= (); > long id=3D-1; while (rs.next()) { id =3D 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("addNewTravelAgentFrom= ProductionFile",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 - Javaforum at > Nabble.com . > > ------=_Part_12391_20619999.1147801385451 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
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 day= s I used to write a statement such as the one below to get the the GENERATE= D_KEYS. in other words, this statement return the id of the new recod. Stat= ement stmt1 =3D=20 con.createStatement(); stmt1.executeUpdate(query1, Statement.RETURN_GENERAT= ED_KEYS); ResultSet rs =3D stmt1.getGeneratedKeys(); long id=3D-1; while (r= s.next()) { id =3D rs.getLong(1); } How can this be done using iBatis? I me= an my xml file looks like this: INSERT INTO employee (First_Name, Last_Name= , Branch) VALUES (#firstName#,#lastName#,#branch#) and the call is: try{=20 ibatis.getSqlMap().executeUpdate("addNewTravelAgentFromProductionFile&= quot;,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=20

View this message in context: get id= with iBatis (Statement.RETURN_GENERATED_KEYS)
Sent from the iBATIS - User - Java forum at Nabble.com.
 

------=_Part_12391_20619999.1147801385451--