JDBC-SQLite 应用程序的调试和运行配置期间的不同结果
/* 问题已回答 */
您好,我正在使用 Eclipse 3.6.1 (Helios),并且通过 JDBC 接口使用 SQLite 数据库。问题是我在调试和运行模式下得到不同的结果。这是测试用例:
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();
}
}
我尝试了 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) 和 Xerial SQLite JDBC 驱动程序(它是 Zentus 的扩展,尝试过 3.6.20 和 3.7.2),用于不同的 SQLite 测试数据库。
如果我在运行配置下运行它,它工作正常(打印 true
和所需的对象),但是当我尝试逐步调试(使用断点,然后是 Step Over)时,它总是打印 false并且 getObject
由于不同原因失败(ch-werner impl 下的 java.lang.ArrayIndexOutOfBoundsException: 2 >= 1
和 java.lang.IllegalStateException: SQLite JDBC :在另外两个情况下内部状态不一致)。没有设置 JVM 参数,只是从头开始编写代码。我未能在 NetBeans 6.9 下重现此错误。
我做错了什么还是什么?
/* 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用调试配置,但只是点击“go”(或 Netbeans 使用的任何内容)而不是逐行逐行执行,会发生什么情况?
我猜测是你有一个手表正在评估一些具有副作用的方法(例如
rs.next()
)并搞乱应用程序的状态,如下所示你跨过线。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.如果您要在每个断点之后对 getX() 进行监视,调试器将调用 getX() 并且 y 将增加 1。并且您的程序将具有与运行模式不同的行为。
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.