aspose file tools
The moose likes JDBC and the fly likes id of the new field in my table Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "id of the new field in my table" Watch "id of the new field in my table" New topic
Author

id of the new field in my table

Grégoire Berclaz
Greenhorn

Joined: Feb 19, 2003
Posts: 28
Hello,
I insert into a table new informations. I like to know the id of this. How can I do?
@+
Greg
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

What database and what driver are you using?
Grégoire Berclaz
Greenhorn

Joined: Feb 19, 2003
Posts: 28
A mySQL database with a jdbc connection
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Well, you should be able to do
SELECT LAST_INSERT_ID() right after your INSERT statement.
Depending on your JDBC driver version you might be able to use the public int executeUpdate(String SQL, int autoGeneratedKeys) method. This only works with JDBC 3.0 specifications though.
If you aren't already, I highly recomend using the Connector-J Driver.
Good luck.
Grégoire Berclaz
Greenhorn

Joined: Feb 19, 2003
Posts: 28
Tks!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: id of the new field in my table
 
Similar Threads
row id to display tag
Regarding Database Index
MSAccess last insert ID ?
How to override table and apply style .
get the last ID in the auto incremented field