Java 不运行带参数的准备语句
我正在使用PreparedStatement 来查询我的表。不幸的是,我没能做到这一点。
我的代码就像这样简单:
PreparedStatement preparedStatement = connection.prepareStatement(
"Select favoritefood from favoritefoods where catname = ?");
preparedStatement.setString(1, "Cappuccino");
ResultSet resultSet = preparedStatement.executeQuery();
抛出的错误是java.sql.SQLException:ORA-00911:无效字符
。就好像它从未运行过给定的参数一样。
感谢您抽出时间。我花了一天的时间来调试这个,但仍然不成功。
正如 Piyush 提到的,如果我省略语句末尾的分号,则会抛出一个新错误。 java.sql.SQLException:ORA-00942:表或视图不存在
。但我可以向你保证这张桌子确实存在。
更新
拍摄。我编辑了错误的sql。现在成功了。谢谢您的宝贵时间。
I am using PreparedStatement to query my table. Unfortunately, I have not been able to do so.
My code is as simple as this:
PreparedStatement preparedStatement = connection.prepareStatement(
"Select favoritefood from favoritefoods where catname = ?");
preparedStatement.setString(1, "Cappuccino");
ResultSet resultSet = preparedStatement.executeQuery();
The error thrown is java.sql.SQLException: ORA-00911: invalid character
. As if it never run through the parameter given.
Thanks for your time. I've spend a day to debug this yet still unsuccessful.
As mention by Piyush, if I omit the semicolon at the end of statement, a new error is thrown. java.sql.SQLException: ORA-00942: table or view does not exist
. But I can assure you this table is indeed exist.
UPDATE
shoot. i edited the wrong sql. now it is successful. thx for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试绑定显示的 sql 中的值并从 SQL 提示符或任何 SQL 编辑器执行它,您是否会收到此错误?
确保您的查询末尾或查询中的任何位置都没有分号(“;”)。
Do you get this error if you try binding values from the shown sql and excute it from the SQL prompt or any SQL editor?
Make sure your query is not having semicolon (";") at the end of it or anywhere in the query.
尝试以这种方式给出..
try giving it this way..