Unix Technical Forum

Cant get @@IDENTITY

This is a discussion on Cant get @@IDENTITY within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> I have a table TIMECARDBATCH which has an identity column as its primary key. Now i have an INSERT ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 10:01 PM
JY
 
Posts: n/a
Default Cant get @@IDENTITY

I have a table TIMECARDBATCH which has an identity column as its primary
key. Now i have an INSERT statement which I want to execute and then get the
key generated for the new row. So what I did is :

String sqlStatement = "INSERT INTO TIMECARDBATCH ( name, desc ) VALUES (
'TOR', 'Toronto' )";
slqStatement += " SELECT @@IDENTITY";

Connection cx = null;
Statement stmt = null;
ResultSet rs = null;
int intReturnValue = -1;

try {
cx.prepareCall( sqlStatement );
stmt.execute();
rs = stmt.getResultSet();
if (rs != null) {
rs.next();
intReturnValue = rs.getInt(1);
}
}...

Whats happening is that I am getting rs as null. As a result I cant get the
identity generated. Any reason why this is happening?

Application Server: JBoss 3.2.3
Database: MS SQL Server 2000
JDBC Driver: MS SQL Server JDBC Driver


Thanks




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com