Re: preparedStatement.getGeneratedKeys() exception.
Posted by: Mark Matthews
Date: November 05, 2004 03:57PM

> I am not trying to update a row, I am trying to insert a row and get the auto-gen-key back for the
> newly inserted row via getGeneratedKeys() after the pstmt.execute() is called.
> In this case I inserted a new row for dp_objtype and expect to get the objtypeid back in the ResultSet of
> getGeneratedKeys().

Yes, but then you're doing this (according to your prior posts), so I'm confused. You're treating something that obviously isn't an updatable result set like it is:

resultSet = pstmt.getGeneratedKeys();
if (resultSet != null &&
newid = resultSet.getInt(1);
resultSet.updateInt(1, newid+1);
This result set is not updatable, why are you trying to call updateInt() on it????????

> Maybe my question is not to expect to use the updateable resultset, but why did pstmt.execute()
> expect an updateable resultset when the Connection.preparedStatement(string, return_auto_genkey) is used.

It _doesn't_...Your code is calling ResultSet.updateInt(), which is only valid for updatable result sets. Result sets returned from getGeneratedKeys() are _never_ updatable.

> When I use pstmt returned from Connection.preparedStatement(string), things work;
> but I cannot get the generated key.

That's to be expected, since you didn't tell the driver you wanted them :)

Explain why you want to call ResultSet.updateInt(), and maybe we'll get this figured out, but it appears you think ResultSet.updateInt() is going to do something with a generated key, but I'm still trying to figure out what you believe that 'something' is :(


Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.