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.
I know that, but that isn't what he asked.
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.
-- Paul DuBois, MySQL Documentation Team Madison, Wisconsin, USA MySQL AB, www.mysql.com
MySQL Users Conference: April 14-16, 2004 http://www.mysql.com/uc2004/
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]