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




.



Relevant Pages

  • HELP: Dropped table column causes sp_addmergearticle to fail with replication
    ... I'm setting up merge replication on sql server 2000 sp3. ... there is no identity column in this table ... The article 'tkDPLRS' could not be added to the publication 'TEST1'. ...
    (microsoft.public.sqlserver.replication)
  • Re: How to insert auto increment?
    ... And there are no other column involved except IDENTITY column. ... single row will do the same thing). ... INSERT INTO tbl DEFAULT VALUES; ... State what version of SQL Server you are using and specify the content ...
    (microsoft.public.sqlserver.mseq)
  • Re: @@Identity
    ... How Does SQL Server Manage Identity Values? ... When you add a row to a table with an Identity column you don't include a ... A scope is a module -- a stored procedure, trigger, function, or ... > If you are inserting a row with your ADO.Net code that will increment the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: cluster index and identity
    ... Hot spotting data gives the cache manager something to grab hold of. ... Clustering on a narrow unique key also has benefits, ... I do not use the identity column as my Primary Key. ... I support the Professional Association for SQL Server ...
    (microsoft.public.sqlserver.server)
  • Re: Adding a key to MS Access Table
    ... > SQL Server by Using Visual C# .NET ... > miha at rthand com ... >> I am unable to insert new rows into an SQL table with a Identity Column ... >> Identity column is also the Primary Key). ...
    (microsoft.public.dotnet.languages.vb)

Loading