Java does not run provisioning instructions with parameter

I am using PreparedStatement to query my table. Unfortunately, I could not do this.

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();

Thrown error java.sql.SQLException: ORA-00911: invalid character. As if it never goes through the given parameter.

Thank you for your time. I spent a day debugging this, but still unsuccessfully.

As Piyush mentions, if I omit the semicolon at the end of the statement, a new error occurs. java.sql.SQLException: ORA-00942: table or view does not exist. But I can assure that this table really exists.

UPDATE

shoot. I edited the wrong sql. now it is successful. Thanks for your time.

+3
source share
2 answers

, sql SQL SQL? , ( ";" ) .

+2

.

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

Source: https://habr.com/ru/post/1795952/


All Articles