It is best to set the column to auto-increment and put the unique constraint on it. Which programming language are you using?
If JAVA, the mm.mysql driver has a method that does what you want: org.gjt.mm.mysql.Statement stmt = (org.gjt.mm.mysql.Statement)con.createStatement(); int Results = stmt.executeUpdate(sql); applicantID = stmt.getLastInsertID(); applicant.setApplicantID((int)applicantID); If PERL, dbi will return the row # you just inserted using: $statement_handle->{insertid} If PHP, This returns the ID number used for the last INSERT statement: $id_num = mysql_insert_id(); If C, Returns the last number generated for an AUTO_INCREMENT field: id = mysql_insert_id(&mysql); printf("The new ID is %d\n", id); When using an ORACLE database, I generally use a sequence generator. I first make a call to get the next number in the sequence, then use that number as the key for my insert. --Jay Gardner -----Original Message----- From: Jay Gardner [mailto:[EMAIL PROTECTED]] Sent: Sunday, April 07, 2002 12:02 AM To: Tomcat Users List Subject: RE: saving object What database are you using? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 06, 2002 9:15 PM To: Tomcat Users List Subject: Re: saving object I have done this with some row_id defined to be auto-insert on mysql. With auto-insert you know it will be unique but might want to make that a constraint. insert .....blah blah select max(row_id) - yields the number of the last tx. row_id is just an example for your purpses. Good luck At 01:41 PM 4/5/02, you wrote: >a little bit off topic. > >I have a table with each row corresponds to a javabean object. The objects >don't >necessarily have a primary key, so i use a sequence number as its primary >key, and a >trigger to assign the sequence number to its ID column when a new object is >inserted >into the database. > >However, after I insert the object into the table, how can i know the >object's ID in the >table? If I simply do a "..._seq.cur_val", it is not safe when multiple >users can access >the database and save their javabean into it at the same time. > >How could you guys accomplish that? > > >-- >To unsubscribe: <mailto:[EMAIL PROTECTED]> >For additional commands: <mailto:[EMAIL PROTECTED]> >Troubles with the list: <mailto:[EMAIL PROTECTED]> -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]> -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]> -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>