aspose file tools
The moose likes JDBC and the fly likes Obtaining auto created id upon finishing insert Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Obtaining auto created id upon finishing insert" Watch "Obtaining auto created id upon finishing insert" New topic
Author

Obtaining auto created id upon finishing insert

D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 471
I'm working on a customer service system which return a customer a ticket number after placing a request. A ticket number is an id in request table, like:

table request
id number
request string
subject string
customer_id number

I use insert like:

I'd like to know ticket id after insertion. Will it be reliable in multi requests environment if I use for getting id under the same transaction the following query:


Is there any more elegant way to do that?


Get power of your iPod with MediaChest | Minimal J2EE container is here | Light weight full J2EE stack | My blog | Co-author of "Windows programming in Turbo Pascal"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26496
    
  78

In JDBC 3, you can use Statement.RETURN_GENERATED_KEYS to have the database return the values. For older versions of JDBC, your solution is best.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 471
Cool, thanks.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Obtaining auto created id upon finishing insert
 
Similar Threads
Java Persistence API
Designing in Hibernate
Reading All the records from a table + Hibernate
JPA-Hibernate One-to-One Bidirectional Relationship issue
problem with MS Access and max