I've got a problem with the latest 3.1 nightly builds of the jdbc
driver.
I get a NullPointerException by calling getInt() in the resultset of a
PreparedStatement (but not in a Statement) if the value in the selected
column is NULL. It should return some valid int value, and set the
wasNull() flag to true.
<code-snippet>
/**
* In advance, Prepare a table with one int column in it, and one row
with NULL.
*
DROP TABLE IF EXISTS TestNullInt;
CREATE TABLE TestNullInt ( i int );
INSERT INTO TestNullInt values ( null );
*/
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer strSql = new StringBuffer();
pstmt = m_Conn.prepareStatement("SELECT i FROM TestNullInt");
rs = pstmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
boolean bRow = rs.next();
System.out.println(rs.getInt(1));
</code-snippet>
Result:
java.lang.NullPointerException
at com.mysql.jdbc.ResultSet.getNativeInt(ResultSet.java:3920)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1319)
at testMySqlNullInt.Query()
Thanks,
Kevin
| Thread |
|---|
| • preparedStatement + null value + rs.getInt() == NullPointerException | Kevin Fries | 23 May |