SQLException:JZ0S4:无法执行空(零长度)查询。 关于准备好的声明
这是一个在连接上执行PreparedStatements 的类。
public class doSomething {
private PreparedStatement ps;
public setPS (Connection conn) throws SQLException {
String sql = "select * from table where id = ?";
ps = conn.prepareStatement(sql);
}
public void runSomething(String var){
ps.setString(1,var);
ResultSet rs = ps.executeQuery();
...
}
}
我
doSomethingInstance.setPS(conn);
doSomethingInstance.runSomething(var);
从另一个类调用,这会抛出异常,异常
ResultSet rs = ps.executeQuery();
是 SQLException:JZ0S4:无法执行空(零长度)查询。 关于准备好的声明。 我不明白为什么。 有人看到我在这里做错了什么吗?
谢谢!
Heres a class executing PreparedStatements on a Connection.
public class doSomething {
private PreparedStatement ps;
public setPS (Connection conn) throws SQLException {
String sql = "select * from table where id = ?";
ps = conn.prepareStatement(sql);
}
public void runSomething(String var){
ps.setString(1,var);
ResultSet rs = ps.executeQuery();
...
}
}
I call
doSomethingInstance.setPS(conn);
doSomethingInstance.runSomething(var);
from another class and this throws and exception at the
ResultSet rs = ps.executeQuery();
The exception is SQLException: JZ0S4: Cannot execute an empty (zero-length) query. on a Prepared Statement. I cant understand why. Does anyone see what Iam doing wrong here?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
返回并直接从源文件复制代码,然后编辑您的问题。 您有一个潜在的歧义:您的第一个片段将准备好的语句称为“preparedStatement”,然后更改为“prepareStatement”(不带“d”)。 清晰地查看源代码将使隔离问题变得更加容易。 您有两个变量还是您的示例输入错误?
[之后...]
感谢您更新您的代码。 我没有看到它有明显的问题。 您是否使用调试器(例如,在 Eclipse 中)单步调试它以确保这两个方法按预期被调用?
Go back and copy the code straight from your source file, then edit your question. You have a potential ambiguity: Your first fragment calls the prepared statement "preparedStatement", then you change to "prepareStatement" (without the "d"). Having a clean look at your source code will make isolating the problem easier. Do you have two variables or did you mistype your example?
[later...]
Thanks for updating your code. I'm not seeing an obvious problem with it. Have you stepped through it with a debugger (e.g., in Eclipse) to ensure that the two methods are being called as expected?
这个问题已经被修复了。 数据库权限有问题。 捕获并打印堆栈跟踪
表明未找到查询正在访问的表。 我仍然需要弄清楚为什么抛出 SQLException: JZ0S4: Cannotexecute anempty (zero-length) query 。
感谢您的时间和考虑。
罗汉
This issue has been fixed folks. There was a problem with the database permissions. Catching and printing the stacktrace on
indicated that the table being accessed by the query was not found. I still have to figure out why the SQLException: JZ0S4: Cannot execute an empty (zero-length) query is being thrown.
Thanks for your time and consideration.
Rohan
你能在执行查询之前打印sql的内容吗? 我怀疑它正在丢失内容
can you print the contents of sql before executing the query? I suspect it's losing it's contents
var 是否非空? var 的类型是否正确(我认为是 int 而不是 String?)
Is var non null? Is var of the correct type(int instead of String I would think?)