
| Key: |
DERBY-186
|
| Type: |
Bug
|
| Status: |
Closed
|
| Resolution: |
Fixed
|
| Priority: |
Major
|
| Assignee: |
Unassigned
|
| Reporter: |
George Baklarz
|
| Votes: |
0
|
| Watchers: |
0
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Windows XP SP1 Professional
|
|
| Resolution Date: |
06/Apr/05 10:08 AM
|
|
Bizarre error. Not sure if this is a JDBC, Derby, or Java issue.
An opened result set has 4 records. A call to relative(3) while on row 3 should result in isAfterLast=true, and isFirst, isBeforeFirst, and IsLast set to false. However, the result is isAfterLast=True and isFirst=True.
ij
connect 'IsAfter;create=true';
create table x (a char(1));
insert into x values '1','2','3','4';
quit;
import java.sql.*;
public class ErrIsFirst {
public static void main(String argv[]) throws SQLException {
Connection conn = null;
Statement s = null;
ResultSet rs = null;
String DerbyDriver = "org.apache.derby.jdbc.EmbeddedDriver";
String returnValue;
try {
Class.forName(DerbyDriver).newInstance();
}
catch (Exception NoDriver) {
System.out.println("Derby driver not found: " + DerbyDriver);
NoDriver.printStackTrace();
System.exit(1);
}
try {
conn = DriverManager.getConnection("jdbc:derby:IsAfter");
s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = s.executeQuery( "SELECT A FROM X");
rs.next(); // First Record
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(2);
System.out.println("isFirst=" + rs.isFirst() + " isLast=" + rs.isLast() + " isAfterLast=" + rs.isAfterLast());
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(-2);
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(10);
System.out.println("isFirst=" + rs.isFirst() + " isLast=" + rs.isLast() + " isAfterLast=" + rs.isAfterLast());
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.close();
s.close();
}
catch (SQLException se) {
String SQLState = se.getSQLState();
String SQLMessage = se.getMessage();
System.out.println("Error = "+SQLState);
System.out.println(SQLMessage);
}
}
}
The results on my system are:
Value=1
isFirst=false isLast=false isAfterLast=false
Value=3
Value=1
isFirst=true isLast=false isAfterLast=true
Error = 24000
Invalid cursor state - no current row.
If you eliminate the first println call to isFirst() you get the following (correct) results.
Value=1
Value=3
Value=1
isFirst=false isLast=false isAfterLast=true
Error = 24000
Invalid cursor state - no current row.
Okay, so where did we go wrong?
|
|
Description
|
Bizarre error. Not sure if this is a JDBC, Derby, or Java issue.
An opened result set has 4 records. A call to relative(3) while on row 3 should result in isAfterLast=true, and isFirst, isBeforeFirst, and IsLast set to false. However, the result is isAfterLast=True and isFirst=True.
ij
connect 'IsAfter;create=true';
create table x (a char(1));
insert into x values '1','2','3','4';
quit;
import java.sql.*;
public class ErrIsFirst {
public static void main(String argv[]) throws SQLException {
Connection conn = null;
Statement s = null;
ResultSet rs = null;
String DerbyDriver = "org.apache.derby.jdbc.EmbeddedDriver";
String returnValue;
try {
Class.forName(DerbyDriver).newInstance();
}
catch (Exception NoDriver) {
System.out.println("Derby driver not found: " + DerbyDriver);
NoDriver.printStackTrace();
System.exit(1);
}
try {
conn = DriverManager.getConnection("jdbc:derby:IsAfter");
s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = s.executeQuery( "SELECT A FROM X");
rs.next(); // First Record
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(2);
System.out.println("isFirst=" + rs.isFirst() + " isLast=" + rs.isLast() + " isAfterLast=" + rs.isAfterLast());
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(-2);
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.relative(10);
System.out.println("isFirst=" + rs.isFirst() + " isLast=" + rs.isLast() + " isAfterLast=" + rs.isAfterLast());
returnValue = rs.getString("A");
System.out.println("Value="+returnValue);
rs.close();
s.close();
}
catch (SQLException se) {
String SQLState = se.getSQLState();
String SQLMessage = se.getMessage();
System.out.println("Error = "+SQLState);
System.out.println(SQLMessage);
}
}
}
The results on my system are:
Value=1
isFirst=false isLast=false isAfterLast=false
Value=3
Value=1
isFirst=true isLast=false isAfterLast=true
Error = 24000
Invalid cursor state - no current row.
If you eliminate the first println call to isFirst() you get the following (correct) results.
Value=1
Value=3
Value=1
isFirst=false isLast=false isAfterLast=true
Error = 24000
Invalid cursor state - no current row.
Okay, so where did we go wrong?
|
Show » |
|
I have small fix going for this which I am still testing. Will update when I get some results.
~ Shreyas