Description:
PreparedStatement.toString() shows number values as null.
I did not test all number types!
How to repeat:
import com.mysql.jdbc.jdbc2.optional.*;
import javax.sql.*;
import java.sql.*;
public class Test {
private static final String server = "localhost";
private static final String database = "test";
private static final String username = "root";
private static final String password = "root";
private Statement stmt;
public static void main (String [ ] args)
{
try
{ System.err.println ("Initialize datasource");
MysqlDataSource ds = new MysqlDataSource();
ds.setServerName (server);
ds.setDatabaseName (database);
ds.setUser (username);
ds.setPassword (password);
System.err.println ("Setup database connection");
Connection conn = ds.getConnection();
test (conn);
}
catch (Exception e)
{ e.printStackTrace (System.err);
System.exit (1);
}
}
private static void test (Connection conn) throws Exception
{
Statement stmt = conn.createStatement();
try {
stmt.executeUpdate ("DROP TABLE IF EXISTS test1");
stmt.executeUpdate ("CREATE TABLE test(field1 INTEGER, field2 DOUBLE)");
stmt.executeUpdate ("INSERT INTO test (field1, field2) VALUES (0,1),(1,2.5),(2,3)");
PreparedStatement ps =
conn.prepareStatement ("SELECT * FROM test WHERE field1 = ? OR field2 = ?");
ps.setObject (1, new Integer (2));
ps.setObject (2, new Double (2.5));
System.out.println ("PS: " + ps.toString());
ResultSet rs = ps.executeQuery();
while (rs.next())
{ Integer i = (Integer) rs.getObject ("field1");
System.out.println ("I: " + i);
Double d = (Double) rs.getObject ("field2");
System.out.println ("D: " + d);
}
ps.close();
}
finally {
stmt.executeUpdate ("DROP TABLE IF EXISTS test");
}
}
}
Suggested fix:
None.