Bug #11990 getString after moveToCurrentRow produces null value
Submitted: 17 Jul 2005 19:13 Modified: 17 Oct 2005 19:42
Reporter: Johan Kustermans Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10 OS:Windows (Windows)
Assigned to: Mark Matthews CPU Architecture:Any

[17 Jul 2005 19:13] Johan Kustermans
Description:
After a call of moveToInsertRow() followed by a call of moveToCurrentRow() for an updateable resultset, the getString(int i) method produces null.

How to repeat:
Class.forName("com.mysql.jdbc.Driver").newInstance();    
conn = DriverManager.getConnection("jdbc:mysql://localhost/test?
user=root&password=*****");
      
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

ResultSet rs = s.executeQuery("select * from postnummers");

rs.next();
rs.moveToInsertRow();
rs.updateString(1,"3000");
rs.updateString(2,"Leuven");
rs.insertRow();
           
rs.moveToCurrentRow();
System.out.println(rs.getString(1));

                       
            

Suggested fix:
Have a look at the source code of UpdateableResultSet in the method moveToInsertRow() (line 910-914?)

this.thisRow = new byte[numFields][];
this.onInsertRow = true;
this.doingUpdates = false;
this.savedCurrentRow = (byte[][]) this.thisRow;
this.thisRow = new byte[numFields][];

It seems to me that the uppermost statement this.thisRow = new Byte[numFields][] should be removed in order to get this.savedCurrentRow = (byte[][])  this.thisRow to work properly.
[18 Jul 2005 9:52] Vasily Kishkin
Could you please write here table definitions ?
[18 Jul 2005 10:31] Johan Kustermans
CREATE TABLE postnummers 
(postnummer CHAR(4) PRIMARY KEY, gemeente VARCHAR(20))

INSERT INTO postnummers VALUES ('3000','Leuven'),('3001','Heverlee'),('1050','Brussel')
[19 Jul 2005 15:49] Aleksey Kishkin
Wrote a test case (attached) and got:

E:\connj3.1.10>"jdbc:mysql:///test?user=root" -cp .;my10.jar;junit.jar Bug11998
.Loading JDBC driver 'com.mysql.jdbc.Driver'
Done.

Done.

Connected to 4.1.12a-nt
F
Time: 0,563
There was 1 failure:
1) testbug11990(Bug11990)junit.framework.AssertionFailedError:  field is null
        at Bug11990.testbug11990(Bug11990.java:31)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at Bug11990.main(Bug11990.java:41)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0
[19 Jul 2005 15:49] Aleksey Kishkin
testcase

Attachment: Bug11990.java (text/x-java), 1.16 KiB.