aspose file tools*
The moose likes JDBC and the fly likes Getting unique ID for INSERT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting unique ID for INSERT" Watch "Getting unique ID for INSERT" New topic
Author

Getting unique ID for INSERT

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi,

I have a small problem I have come accross, which I can't see an obious way round.

I have a RegistrationServlet (for creating a new user) which inserts the details of the new user into two seperate tables in a MS SQL database.

The first insert puts the users personal data into a table called tblUsers (name, dob, tel no, address, etc). The second insert puts the users security details into a table called tblUserSecurity (username, password, etc).

The problem I have is, the only way to uniquely identify the user is from the ID column (from tblUsers) which is set as the primary key and automatically created for each record added, I need to somehow take this value for the new user and insert it into the tblSecurity table along with the username, password etc as a way of linking the user to their security details.

Any help would be greatly appreciated.

Cheers
praveen kanakarajan
Ranch Hand

Joined: Apr 27, 2005
Posts: 54
im not a great expert.i think u can get the value of last identity by using the query
select @@identity
will return the latest identity value.Just try this im not sure.but hope will help you
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Cheers for that, but I have found a way to get the last record eneterd (I think), but tanks anyway. Always nice to have a plan 'B'.
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
You may have solved this differently, but if I understand you problem, you could use something along the lines of:



Hope this helps (someone!)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting unique ID for INSERT
 
Similar Threads
realm,acls in weblogic
How to handle Security in a Webapp with a JDBCRealm
Username and Passwords
I hope someone replies to this one
encrypting passwords