Re: preparedStatement.getGeneratedKeys() exception.
Posted by: Alex Cheung
Date: November 04, 2004 04:07PM

Sorry, my bad (been trying different things, the original problem I ran into is as follow); problem description changed. Here is the code and the exception.

- alex
pstmt = conn.prepareStatement(psqlstmt,Statement.RETURN_GENERATED_KEYS);
// populate the '?' parameters in PreparedStatement [pstmt].
for (int i=0; i < data.length; i++)
System.out.println("pstmt.setObject("+(i+1)+","+ data + ")");
pstmt.setObject(i+1, data);
resultSet = pstmt.getGeneratedKeys();
if (resultSet != null &&
newid = resultSet.getInt(1);
resultSet.updateInt(1, newid+1);
System.out.println("newid = " + newid);
System.out.println("resultset is NULL.");


com.mysql.jdbc.NotUpdatable: Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for
more details.

How do I use both preparedstatement and CONCUR_UPDATEABLE? java.sql.Connection only supports 2 prepareStatement() API for using getGeneratedKeys() and it does not provide a way to specify the ResultSet type like createStatement() call.


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.