Java不运行带参数的prepare语句 [英] Java does not run prepare statements with parameter

查看:524
本文介绍了Java不运行带参数的prepare语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PreparedStatement查询我的表。不幸的是,我无法这样做。

I am using PreparedStatement to query my table. Unfortunately, I have not been able to do so.

我的代码很简单:

PreparedStatement preparedStatement = connection.prepareStatement(
"Select favoritefood from favoritefoods where catname = ?");

preparedStatement.setString(1, "Cappuccino");                
ResultSet resultSet = preparedStatement.executeQuery();

抛出的错误是 java.sql.SQLException:ORA-00911:无效字符。好像它永远不会通过给定的参数运行。

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.

正如Piyush所提到的,如果我在语句结尾处省略分号,则会抛出新的错误。 java.sql.SQLException:ORA-00942:表或视图不存在。但我可以向你保证这张桌子确实存在。

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.

更新

拍摄。我编辑了错误的sql。现在它成功了。 thx你的时间。

shoot. i edited the wrong sql. now it is successful. thx for your time.

推荐答案

如果尝试从显示的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.

这篇关于Java不运行带参数的prepare语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆