This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes id of the new field in my table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What database and what driver are you using?


GenRocket - Experts at Building Test Data
Grégoire Berclaz
Greenhorn

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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!
 
Don't get me started about those stupid light bulbs.
 
subject: id of the new field in my table
 
Similar Threads
row id to display tag
get the last ID in the auto incremented field
How to override table and apply style .
Regarding Database Index
MSAccess last insert ID ?