File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 15300
    
    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: 15300
    
    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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: id of the new field in my table