Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

java - 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 fine (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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...