Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 14738 invoked from network); 19 Aug 2002 15:51:18 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 19 Aug 2002 15:51:18 -0000 Received: (qmail 2527 invoked by uid 97); 19 Aug 2002 15:50:35 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 2482 invoked by uid 97); 19 Aug 2002 15:50:34 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 2467 invoked by uid 98); 19 Aug 2002 15:50:34 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: <01af01c24797$83ff84f0$5cfaa8c0@Hornet> From: "Mark O'Driscoll" To: "Tomcat Users List" References: Subject: Re: servlet-jdbc-SQL server Date: Mon, 19 Aug 2002 16:45:59 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N MySQL has a last_insert_id() function which you can use on a connection ----- Original Message ----- From: "Mike Jackson" To: "Tomcat Users List" Sent: Monday, August 19, 2002 4:38 PM Subject: RE: servlet-jdbc-SQL server > With oracle there's a way to specify that a insert does a return, it's > something like "insert into tablea ( a ) values ( 'a' ) returning id". > I know this isn't oracle that you're asking about, but you might try > using that syntax on ms sql and see what happens. Or it might help to > find it in their documentation (there's a guide oracle vs ms sql in the > documentation). > > --mikej > -=----- > mike jackson > mjackson@cdi-hq.com > > > -----Original Message----- > > From: Matt Brennan [mailto:matt@classforge.com] > > Sent: Monday, August 19, 2002 8:36 AM > > To: tomcat-user@jakarta.apache.org > > Subject: servlet-jdbc-SQL server > > > > > > Just taking some stumbling first steps talking to SQL server from a > > servlet using the Microsoft JDBC driver. Servlet container is tomcat > > 4.0.4. Quick question if I may: > > > > I need to insert a row into an SQL Server table and have the servlet > > generate a page that includes an automatically generated IDENTITY from > > the newly created row. How after the insert can I find the generated ID > > without conducting a subsequent query (which would have no guarantee of > > returning uniquely the newly inserted record)? > > > > // 'con' is a connection to MS-SQLserver with SelectMethod=cursor > > Statement state = con.createStatement( > > ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); > > > > // Generate an empty result set > > ResultSet content = state.executeQuery(sqlQuery); > > > > content.moveToInsertRow(); > > // Column 1 is id int IDENTITY NOT NULL PRIMARY KEY > > // Column 2 is name VARCHAR(20) > > content.updateString (2, "something"); > > content.insertRow(); > > > > // If I then query the inserted row, to find the newly generated > > // IDENTITY value I get MIN_INT instead of '1' (the default first > > // identity generated by SQL server if no seed is given) > > int id = content.getInt (1); > > > > Is this some peculiarity of the servlet interface to the driver, to the > > driver itself or just my bad undestanding of the insert process? Is it > > possible to configure the Statement so that the Insert row in the Result > > Set gets updated when the insert takes place and the 'id' gets generated? > > > > Please excuse the fact that this query starts to look more like a JDBC > > query than a tomcat query - not quite sure where the problem lies - > > tomcat+driver? driver? my understanding (most likely!). I am hoping that > > other servlet developers have crossed this bridge before. > > > > matt > > > > > > > > -- > > To unsubscribe, e-mail: > > > > For additional commands, e-mail: > > > > > > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > > -- To unsubscribe, e-mail: For additional commands, e-mail: