Home > Archive > MS SQL Server ODBC > November 2005 > Cant get @@IDENTITY









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Cant get @@IDENTITY
JY

2005-11-15, 8:23 pm

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




Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com