4

Possible Duplicate:
Retrieve id of record just inserted into a Java DB (Derby) database

I have a table in a Derby database with a column created:

id INTEGER GENERATED ALWAYS AS IDENTITY

How do I get the id of the last record inserted? How can I know what is the id of the record I have just inserted?

Community
  • 1
  • 1
mynameisalon
  • 165
  • 2
  • 7

3 Answers3

1

Java's Statement class has getGeneratedKeys(), which is designed to provide that information:

http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGeneratedKeys()

Joseph Ottinger
  • 4,911
  • 1
  • 22
  • 23
1

the IDENTITY_VAL_LOCAL() function should be your friend: http://db.apache.org/derby/docs/10.2/ref/rrefidentityvallocal.html

stevevls
  • 10,675
  • 1
  • 45
  • 50
1

See following SO question: Retrieve id of record just inserted into a Java DB (Derby) database

Community
  • 1
  • 1
Suresh Kumar
  • 11,241
  • 9
  • 44
  • 54