• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting unique ID for INSERT

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'.
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may have solved this differently, but if I understand you problem, you could use something along the lines of:



Hope this helps (someone!)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic