• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto-generated ID number

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using JavaDB (aka Apache Derby). I have a table like this: -


I would like to insert a row into this database and find the auto-generated Token value for the inserted row. It is not obvious how I would do that using JDBC.

Any suggestions?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
In JDBC 3.0, this is easy to do. See this Derby manual page for details.
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How easy is it in JDBC 2?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn,
Some databases provided database specific methods to get the generated keys. Alternatively, you could do a query based on the data you entered (assuming it was distinct) to get the key.

Note that JDBC 3 came out with Java 1.4. So it's been a while since I did it "the old way".
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jeanne
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
In JDBC 3.0, this is easy to do. See this Derby manual page for details.


Thanks. This looks like exactly what I want.

FWIW I got the functionality I needed using the Derby-specific function IDENTITY_VAL_LOCAL(). But the getGeneratedKeys() method looks much better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic