wood burning stoves 2.0*
The moose likes JDBC and the fly likes getGeneratedKeys() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getGeneratedKeys()" Watch "getGeneratedKeys()" New topic
Author

getGeneratedKeys()

Sajan Patel
Ranch Hand

Joined: Oct 25, 2004
Posts: 77
Dear All,
I am trying to retrieve IDENTITY from SQL Server Database. Up to now I was using SP so I using registerOutParameter(1, Types.INTEGER) method. But now I have to use prepared statement.

I have one table in SQL Server database which has one table where IDENTITY is created itself and IDENTITY_INSERT is set to off so no one can insert from outside


// There is another column also name PERSON_ID
String sqlPerson = "INSERT INTO PERSON(NAME, LASTNAME) VALUES (?,?)";

PreparedStatement pstmnt = con.prepareStatement(sqlPerson, Statement.RETURN_GENERATED_KEYS);

pstmnt.setString(1, "Any Name");
pstmnt.setString(2, "Any Last Name");

pstmnt.execute();

ResultSet rs2 = pstmnt.getGeneratedKeys();
int intID = -1;
while(rs2.next()){
intID = rs2.getInt(1);
}

I am having error of java.lang.AbstractMethodError.

I am not sure where is problemm according to me it is right but I am getting error means some thing is wrong.

Thought one
Do I have to mentioin something in sqlPerson like PERSON_ID column name or SET @@IDENTITY ?
Thought two
In Callable Statement we have to register return data and data type do we have to mention something like that some where?

thanks in advance
 
jQuery in Action, 2nd edition
 
subject: getGeneratedKeys()
 
Similar Threads
Could not synchronize database state with session
Repeated updates on EVENT table, in Hibernate one to many mapping
auto insert in jdbc
Hibernate/MSSQL/identity column
Column appears twice - Hibernate generated prepared statement