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 Returning a sequence id Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Returning a sequence id" Watch "Returning a sequence id" New topic
Author

Returning a sequence id

Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Hi all

I am using JDBC to insert a row into a table and the id for that row is created using a sequence. Is there any way to get that sequence number right after you execute or a way to have that value returned.

Thanks,

AMD
Rajasekar Elango
Ranch Hand

Joined: Sep 13, 2004
Posts: 105
Hi Andrew,

Which database are you using..? For informix, you can do something like this.


Check your jdbc provider API, there might be something similar to this. Since this is database dependent, it is not part of standard JDBC API and beware you will lose portability if you use this.

Thanks,
Raja


SCJP 1.4
Andrew Mcmurray
Ranch Hand

Joined: Sep 24, 2005
Posts: 188
Sorry I am using Oracle 10.2. I am trying select seq.nextVal from dual now and it seems to be working. Is this method thread safe?

Thanks,

AMD
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2343

.. sequence.nextval ... Is this method thread safe?

Yes. Oracle guarantees a unique id.

Regards, Jan


OCUP UML fundamental
ITIL foundation
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Returning a sequence id
 
Similar Threads
How to use generators in Composite-id
MySQL + Eclipselink - SEQUENCE table
Link IDs on Page
Referential Integrity: How 2 INSERT the professional way ?
Is this possible using CMP ? [keys from sequences]