yup, that's letting the auto_increment do its job (which is what I do). some folks don't believe in those, and use a separate primary key generating scheme. Many a time I've heard of this "update and retrieve in one select statement", and I think it always has a vaguely Oracle'ish feel to it. So whenever I hear of someone say something like "use one query to generate your next pk".. I always wonder.
> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, September 30, 2004 11:06 PM > To: Tomcat Users List > Subject: RE: method level synchronization doesn't work > > > > > > > > > Is your primary key generated automatically? > If so, the combined insert/query is: > > String stmt="INSERT INTO SOMEFILE (FLD1,FLD2,FLD3) > VALUES(?,?,?)"; > PreparedStatement sql = > conn.prepareStatement(stmt,Statement.RETURN_GENERATED_KEYS); > sql.setInt(1,fld1); > sql.setInt(2,fld2); > sql.setInt(3,fld3); > sql.execute(); > ResultSet rs = sql.getGeneratedKeys(); > if (rs.next()) { > // get generated key > int key=rs.getInt(1); > } > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
