• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Obtaining auto created id upon finishing insert

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34073
335
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic