java SQLite 异常:插入语句不返回语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7052196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite Exception: Insert statement does not return a Statement
提问by Massie
I'm using SQLiteJDBC as the wrapper for an embedded database for my small Java app. Everytime I execute an INSERT statement, I get the following exception:
我使用 SQLiteJDBC 作为我的小型 Java 应用程序的嵌入式数据库的包装器。每次执行 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; maybe SQLiteJDBC is throwing an error because it shouldn't be returning the ResultSet that Statement is asking for?!?
我想知道 JDBC Statement.executeStatement(String) 方法是否正在寻找我返回 ResultSet,但 SQLite 驱动程序知道 INSERT 语句不返回任何内容;也许 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?!?
有任何想法吗?!?
回答by 101100
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. Were you using executeQuery()
?
我什至找不到executeStatement()
任何地方的参考。你在用executeQuery()
吗?
回答by Berni
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