Different results during Debug and Run configurations of JDBC-SQLite app
/* Question answered */
Hi, I am using Eclipse 3.6.1 (Helios) and I work with SQLite database through JDBC interface. The problem is that I'm getting different result under Debug and Run modes. Here is the test case:
public static void main(String[] args){
String db_name = /* path to some SQLite database */;
try {
// If we using ch-werner SQLite Java Wrapper/JDBC Driver
Class.forName("SQLite.JDBCDriver");
// If we using Xerial or Zentus impl.
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:" + db_name);
Statement statement = con.createStatement();
ResultSet rs;
try {
rs = statement.executeQuery("SELECT * FROM sites;");
boolean flag = rs.isBeforeFirst(); // Breakpoint here
System.out.println(flag);
if (flag) rs.next();
System.out.println(rs.getObject(1));
} finally {
statement.close();
con.close();
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
I tried JDK 1.6.0, 1.6.0_23, JRE 1.6.0; 3 implementations of JDBC-SQLite: ch-werner SQLite Java Wrapper/JDBC Driver (r2011-01-06), Zentus SQLiteJDBC (0.5.6) and Xerial SQLite JDBC Driver (which is extended Zentus, tried 3.6.20 and 3.7.2) for different SQLite test databases.
If I run this under Run configuration, it works fin开发者_Go百科e (prints true
and desired object), but when I try step-by-step debugging (using breakpoint, followed by Step Over's), it always prints false and getObject
fails for different reasons (java.lang.ArrayIndexOutOfBoundsException: 2 >= 1
under ch-werner impl, and java.lang.IllegalStateException: SQLite JDBC: inconsistent internal state
under two others). There is no JVM arguments set, just code from scratch. I failed to reprofuce this bug under NetBeans 6.9.
Am I doing something wrong or what?
What happens if you use the debug configuration, but just hit "go" (or whatever Netbeans uses) instead of stepping over each line one by one?
My guess is that you've got a watch which is evaluating some method with side-effects (e.g. rs.next()
) and screwing up the state of the application as you step over lines.
int getX(){
y++;
return x;
}
If you were to put a watch on getX() after every breakpoint the debugger will call getX() and y would increment by 1. And your programm would have a different behaviour from the run mode.
精彩评论