Description:
When using the function:
prepareStatement("SQL STATEMENT",Statement.RETURN_GENERATED_KEYS);
...
and obtaining the ResultSetMetaData object from the generated keys resultset (using the getGeneratedKeys() and the getMetaData() functions), the following
functions (and possibly others) result in an error:
getColumnDisplaySize()
isDefinitelyWritable()
isReadOnly()
isWritable()
The error generated is:
java.lang.NullPointerException
at com.mysql.jdbc.Field.getMaxBytesPerCharacter(Field.java:437)
at com.mysql.jdbc.ResultSetMetaData.getColumnDisplaySize(ResultSetMetaData.java:307)
at hindsight.Test.main(Test.java:22)
This error is repeatable, and an example program that generates this problem is shown in the 'how to repeat' section below (with changes to the SQL statement and database name and login information).
How to repeat:
import java.sql.*;
public class Test
{
public static void main(String[] args) throws Exception
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/hindsight?user=hindsight&password=hindsight");
PreparedStatement stmt = conn.prepareStatement("insert into TradeRange(tradeID,startVolume,endVolume,variablePrice,fixedPrice,useFixed) values(1,200,250,10,10,1);",Statement.RETURN_GENERATED_KEYS);
stmt.executeUpdate();
ResultSet lrs = stmt.getGeneratedKeys();
if(lrs.next())
{
ResultSetMetaData lrsMeta = lrs.getMetaData();
int liDSize = lrsMeta.getColumnDisplaySize(1);
System.out.println(liDSize);
}
lrs.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Suggested fix:
There are no work arounds that have been found.