This discussion is archived
6 Replies Latest reply: Feb 9, 2013 2:25 AM by Murray9654 RSS

How to get the right primary key?

Murray9654 Newbie
Currently Being Moderated
I have multiple clients working at the same time on the same database. i am strong an user information into the database. the primary key is auto generated in the database table. There is no unique column in the user table. I am storing the user information using jdbc and immediately i am fetching the max number of the primary key column and using that as the primary key for the user that i just stored. I see a problem in this. when multiple clients are working at the same time if one client stored the user info and then another client stored the user info, now if first client fetches the max number of the primary key column it gives the primary key of the user that was stored by the second client. so in jdbc how do i get the right primary key? what should be my approach? how to do it?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points