简体   繁体   English

SQLite 异常:插入语句不返回语句

[英]SQLite Exception: Insert statement does not return a Statement

I'm using SQLiteJDBC as the wrapper for an embedded database for my small Java app.我正在使用 SQLiteJDBC 作为我的小型 Java 应用程序的嵌入式数据库的包装器。 Everytime I execute an INSERT statement, I get the following exception:每次执行 INSERT 语句时,都会出现以下异常:

query does not return ResultSet查询不返回 ResultSet

I am wondering if the JDBC Statement.executeStatement(String) method is looking for me to return a ResultSet, but that the SQLite driver knows that INSERT statements don't return anything;我想知道 JDBC Statement.executeStatement(String) 方法是否正在寻找我返回 ResultSet,但是 SQLite 驱动程序知道 INSERT 语句不返回任何内容; maybe SQLiteJDBC is throwing an error because it shouldn't be returning the ResultSet that Statement is asking for???也许 SQLiteJDBC 抛出错误,因为它不应该返回 Statement 要求的 ResultSet ???

Here is the code that is producing the exception - I have made sure to setup and close all resources properly:这是产生异常的代码 - 我已确保正确设置和关闭所有资源:

statement = con.createStatement();
String sql = "INSERT INTO widgets (widget_age) VALUES (27)";
statement.executeStatement(sql);

Any ideas???有任何想法吗???

When you are making a change and not asking for a result back, you need to call executeUpdate() instead of executeStatement() .当您进行更改而不要求返回结果时,您需要调用executeUpdate()而不是executeStatement()

EDIT编辑

I can't even find a reference to executeStatement() anywhere.我什至在任何地方都找不到对executeStatement()的引用。 Were you using executeQuery() ?您使用的是executeQuery()吗?

Sqlite always returns a message quen you execute a Query. Sqlite 在您执行查询时始终返回消息。

It's normal to have that warning/error, it's simply that no rows where returned so you can't use them in the callback if you defined one.出现警告/错误是正常的,只是没有返回任何行,所以如果你定义了一个,你就不能在回调中使用它们。

PD: I also think you meant executeQuery PD:我也认为你的意思是 executeQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM