JDBC-SQLite应用程序调试和运行配置期间的不同结果 [英] Different results during Debug and Run configurations of JDBC-SQLite app

查看:506
本文介绍了JDBC-SQLite应用程序调试和运行配置期间的不同结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse 3.6.1(Helios),我通过JDBC接口与SQLite数据库一起工作。问题是我在调试和运行模式下得到不同的结果。这是测试用例:

  public static void main(String [] args){
String db_name = / *一些SQLite数据库的路径* /;
try {
//如果我们使用ch-werner SQLite Java Wrapper / JDBC驱动程序
Class.forName(SQLite.JDBCDriver);

//如果我们使用Xerial或Zentus impl。
Class.forName(org.sqlite.JDBC);

连接con = DriverManager.getConnection(jdbc:sqlite:+ db_name);
语句语句= con.createStatement();
ResultSet rs;
尝试{
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();
}
}

我尝试过JDK 1.6.0,1.6.0_23, JRE 1.6.0; JDBC-SQLite的3个实现: ch-werner SQLite Java Wrapper / JDBC驱动程序(r2011-01 -06), Zentus SQLiteJDBC (0.5.6)和用于不同SQLite测试数据库的Xerial SQLite JDBC驱动程序(它是扩展Zentus,尝试3.6.20和3.7.2) p>

如果我在运行配置下运行它,它可以正常工作(打印 true 和所需的对象),但是当我尝试步骤由于不同的原因( java.lang.ArrayIndexOutOfBoundsException(使用断点,其次是Step Over's)),它始终打印为false,并且 getObject :2> = 1 在ch-werner impl和 java.lang.IllegalStateException:SQLite JDBC:不一致的内部状态另外两个)。没有设置JVM参数,只是代码从零开始。我没有在NetBeans 6.9下重新生成此错误。



我做错了什么或什么?

解决方案

如果您使用调试配置,但是只要点击go(或Netbeans使用的任何内容),而不是一个接一个地遍历每行,会发生什么?



我的猜测是你有一个手表,评估一些方法与副作用(例如 rs.next() ),并在您跳过线路时拧紧应用程序的状态。


/* 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?

解决方案

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.

这篇关于JDBC-SQLite应用程序调试和运行配置期间的不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆