Thread: moveToCurrentRow causes ArrayIndexOutOfBoundsException
Below is a small sample code that I tried out and the results are a little surprising to me. Is this expected behavior? In the test code below the query would return zero rows. I am using jdk1.5.0 with pg74.215.jdbc3.jar and PostgreSQL 7.4.7 TEST 1: Code Fragment: String sql = "Select * FROM test_table WHERE id = -1;"; Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = st.executeQuery(sql); rs.next(); rs.moveToInsertRow(); rs.updateString("client_name", "XYZ"); rs.moveToCurrentRow(); Causes: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 at java.util.Vector.elementAt(Vector.java:432) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.moveToCurrentRow(Abstract Jdbc2ResultSet.java:854) at test.<init>(test.java:35) at test.main(test.java:86) Note: Line number 35 is rs.moveToCurrentRow(); TEST 2: Code Fragment: String sql = "Select * FROM test_table WHERE id = -1;"; Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = st.executeQuery(sql); rs.moveToInsertRow(); rs.updateString("client_name", "XYZ"); rs.moveToCurrentRow(); No Exception.
On Wed, 23 Mar 2005, Prasanth wrote: > Below is a small sample code that I tried out and the results are a little > surprising to me. Is this expected behavior? No, that's a bug. moveToCurrentRow was not correctly handling the case where the current row is off the end of the ResultSet. I've fixed it in 8.0 and 8.1dev. > I am using jdk1.5.0 with pg74.215.jdbc3.jar and PostgreSQL 7.4.7 Your stacktrace shows you are using the 8.0 driver. I've put up new versions of the 8.0 jar files here: http://www.ejurka.com/pgsql/jars/prasanth Kris Jurka
> Your stacktrace shows you are using the 8.0 driver. Sorry about that had two jars in my class path. The other one was postgresql-8.0.309.jdbc3.jar > No, that's a bug. moveToCurrentRow was not correctly handling the > case where the current row is off the end of the ResultSet. I've fixed it > in 8.0 and 8.1dev. If I am using 8.0 jar then wasn't the fix there? Any how I tried with the new jar you have provided and seems its working now. Thank you very much for your help. -Prasanth. Kris Jurka wrote: > > On Wed, 23 Mar 2005, Prasanth wrote: > > >>Below is a small sample code that I tried out and the results are a little >>surprising to me. Is this expected behavior? > > > No, that's a bug. moveToCurrentRow was not correctly handling the > case where the current row is off the end of the ResultSet. I've fixed it > in 8.0 and 8.1dev. > > >>I am using jdk1.5.0 with pg74.215.jdbc3.jar and PostgreSQL 7.4.7 > > > Your stacktrace shows you are using the 8.0 driver. > > I've put up new versions of the 8.0 jar files here: > > http://www.ejurka.com/pgsql/jars/prasanth > > Kris Jurka > >
On Wed, 23 Mar 2005, Prasanth wrote: > > No, that's a bug. moveToCurrentRow was not correctly handling the > > case where the current row is off the end of the ResultSet. I've fixed it > > in 8.0 and 8.1dev. > > If I am using 8.0 jar then wasn't the fix there? > Any how I tried with the new jar you have provided and seems its working > now. > I meant that I fixed it since receiving your report which is why I built a current set of jar files for you. The fix is not in the officially released ones. Kris Jurka