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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| Thread Tools | |
| Display Modes | |
|
|