开发者

Java does not run prepare statements with parameter

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.prepareStateme开发者_高级运维nt(
"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.


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..

String query="Select favoritefood from favoritefoods where catname = ?";
preStat = conn.preparedStatement(query);  // conn is the connection object
preStat.setString(1,"Cappuccino");
ResultSet resultSet=preStat.executeQuery();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜