but there are ways to get this value. The Java API handles this case just fine, and I'd be willing to bet other API's do it as well.

here's some simple code to do with the Java API:

String sql = <some insert sql statement>;
Statement stmt = getConnection().createStatement();
stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
setId(rs.getInt(1));     <------ this is the auto_generated row id
stmt.close();

Paul DuBois wrote:
At 17:02 +0000 2/24/04, David Scott wrote:

Hi list peeps....
In many of my projects I have the need to insert a new record into a table and then later on in the script update this record, Right now I am doing this by doing the insert, then immediately doing a Select to return the latest id (unique id) which I store later for my update.


Is there any way I can do an insert and have it return the unique auto-assigned id?


If you mean, can you have the insert statement itself return the ID,
no.  Insert statements don't return records.




--
Jeff Mathis, Ph.D.                      505-955-1434
The Prediction Company                  [EMAIL PROTECTED]
525 Camino de los Marquez, Ste 6        http://www.predict.com
Santa Fe, NM 87505


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to