Description:
I have a table without a primary key. If I try to create a updatable resultset and select all columns from the table, JDBC driver is not able to update the table. This is understandable and totally OK! But if I still try to update the resultset using ResultSet.updateXXX() method I'll first get SQLException and all subsequent ResultSet.updateXXX() method calls produce NullPointerException. Why is that? Shouldn't ResultSet.updateXXX() methods always produce only SQLExceptions if resultset is not updatable?
Teemu
How to repeat:
Table definition:
----------------------------------------
CREATE TABLE `test1` (
`b` varchar(5) NOT NULL default '',
`a` int(11) default NULL
) TYPE=MyISAM
----------------------------------------
Example code:
----------------------------------------
ResultSet rs = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test/?user=xxx&password=xxx");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from test1");
rs.absolute(1);
rs.updateInt(2,1); // The first updateXXX call produce SQLException
}
catch (SQLException e) {e.printStackTrace();}
catch (InstantiationException e) {e.printStackTrace();}
catch (IllegalAccessException e) {e.printStackTrace();}
catch (ClassNotFoundException e) {e.printStackTrace();}
try
{
rs.updateInt(2, 1); // Second updateXXX call produce NullPointerException
}
catch (SQLException e) {e.printStackTrace();}
---------------------------------------