Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getGeneratedKeys()

 
Sajan Patel
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic