5 messages in com.mysql.lists.javaRe: reading the AUTO_INCREMENT value...
FromSent OnAttachments
Bjorn Ehinger03 Feb 2000 00:23 
Don Gourley03 Feb 2000 09:44 
Glenn Crownover03 Feb 2000 17:29 
Mark Matthews04 Feb 2000 05:29 
Mark Matthews04 Feb 2000 05:44 
Subject:Re: reading the AUTO_INCREMENT value...
From:Mark Matthews (mmat@thematthews.org)
Date:02/04/2000 05:29:59 AM
List:com.mysql.lists.java

Which only works if no other queries have been issued on the same connection between the time you issued the query that created an INSERT_ID, and the "SELECT LAST_INSERT_ID() as ID" query. This is the reason I created the method to retrieve it from the Statement, as the last insert ID is returned on every insert statement via the MySQL protocol.

-Mark

Alternately you can do:

ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID() AS ID");

-- ·.¸¸.·´¯`·. Glenn R. Crownover ·.¸¸.·´¯`·. Owner/CEO - Investor's Network Cafe ·.¸¸.·´¯`·. http://www.investnetcafe.com/ ·.¸¸.·´¯`·. reply to: gle@bluejava.com

Don Gourley wrote:

We do this to get the auto-increment key value:

long id = ((org.gjt.mm.mysql.Statement)stmt).getLastInsertID();

where stmt was the handle returned by createStatement().

-Don

At 03:24 AM 2/3/2000 , Bjorn Ehinger wrote:

Hi!

If I have a table in MySQL, defined someting like this (dummy example):

CREATE TABLE objects ( object_ID BIGINT NOT NULL AUTO_INCREMENT, object_name VARCHAR(20) NOT NULL );

When executing the command:

INSERT INTO objects (object_name) VALUES ('hello');

Using JDBC, is there any way I can receive the object_ID generated by the AUTO_INCREMENT?

Thanks. BjornE

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.