Bug #6561 | Connector-J generates null pointer exception | ||
---|---|---|---|
Submitted: | 10 Nov 2004 22:06 | Modified: | 22 Nov 2004 21:11 |
Reporter: | M Wensink | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S1 (Critical) |
Version: | latest snapshot | OS: | Windows (win2k) |
Assigned to: | Hakan Küçükyılmaz | CPU Architecture: | Any |
[10 Nov 2004 22:06]
M Wensink
[11 Nov 2004 21:18]
M Wensink
I have done some further investigation. If I enable dontUnpackBinaryResults, no exception is thrown, but I get wrong information. I the test example this means that I get the rows (2,2) and (2,3). So I get the last row with field1 value of 2 (the other row) in stead of null. I also tried an old snapshot, dated 2004/09/13 18:45:18 $, $Revision: 1.27.4.44, which does not throw an exeception neither gives me wrong information. I hope this will be helpful. Marten
[20 Nov 2004 18:02]
M Wensink
I managed to isolate the bug (se next program). The values of two consecutive fields are interchanged if the value of a preceeding DATE-field is 0. It looks like a very nasty bug! import com.mysql.jdbc.jdbc2.optional.*; 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); ds.setZeroDateTimeBehavior ("convertToNull"); 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 test"); stmt.executeUpdate ("CREATE TABLE test (field1 DATE, field2 integer, field3 integer)"); stmt.executeUpdate ("INSERT INTO test (field1,field2,field3) VALUES (0,NULL,0)"); stmt.executeUpdate ("INSERT INTO test (field1,field2,field3) VALUES ('2004-11-20',NULL,0)"); PreparedStatement ps = conn.prepareStatement ("SELECT * FROM test"); ResultSet rs = ps.executeQuery(); while (rs.next()) { java.sql.Date d = (java.sql.Date) rs.getObject ("field1"); System.out.println ("field1: " + d); Integer i = (Integer) rs.getObject ("field2"); System.out.println ("field2: " + i); i = (Integer) rs.getObject ("field3"); System.out.println ("field3: " + i + "\n"); } ps.close(); } finally { stmt.executeUpdate ("DROP TABLE IF EXISTS test"); } } }
[22 Nov 2004 15:08]
Mark Matthews
I'm not able to repeat this with the November 22 snapshot. The code that unpacks binary result sets from prepared statements has been reworked, so this bug might be fixed. Please re-test with the November 22 snapshot.
[22 Nov 2004 20:53]
M Wensink
You are right. I worked on this problem on last saturday, using the snapshot of that moment. This morning I have tested the new snapshot and the bag seems to be fixed. Hurray!