This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Using SQL Server @@IDENTITY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using SQL Server @@IDENTITY" Watch "Using SQL Server @@IDENTITY" New topic

Using SQL Server @@IDENTITY

Ian Morris

Joined: May 23, 2001
Posts: 7
Please can somebody help with the following question. I am working on a JSP/Servlet application, my servlet inserts a record into a table with an identity column(SQL Server 7). How can I do a "select @@IDENTITY" to see what the last identity inserted was. I would like to capture the identity and display it back using a JSP. Thanks.
Daniel Dunleavy
Ranch Hand

Joined: Mar 13, 2001
Posts: 276
If you write a procedure call to do it you can return it as a result at the end in either a parm out field or a select result like ....

ret_id = @@identity
select ret_id
I agree. Here's the link:
subject: Using SQL Server @@IDENTITY
Similar Threads
How to make this safe
How to know Identity columns of a table?
Binary datatype in MS SQL via JDBC
In need of automatic Id generator code
getting the last inserted value