Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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
Sheriff
Posts: 35976
422
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!