How to get value of a primary key as soon as you inserted it

Here’s an article that talks about how :

And here’s a code snippet:

PreparedStatement ps = conn.prepareStatement(sqlCode,


   //Get the value of the key inserted by this statement
   ResultSet rs = ps.getGeneratedKeys();
   if ( ) {
       // Retrieve the auto generated key(s).
       int key = rs.getInt(1);

This entry was published on January 20, 2009 at 3:18 pm and is filed under Database, Java/J2EE. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: