正确的语法在'?'附近使用 [英] right syntax to use near '?'
本文介绍了正确的语法在'?'附近使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java代码:
I have a Java-code:
String searchPerson = "select * from persons where surname like ? and name like ?";
//connect to DB
PreparedStatement statement = connect.prepareStatement(searchPerson);
statement.setString(1,"%"+ surname + "%");
statement.setString(2, "%" + name + "%");
ResultSet resultPerson = statement.executeQuery(searchPerson);
//..code
然后我有SQLException:
Then I have SQLException:
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'?'附近使用正确的语法。
you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?'
推荐答案
你应该执行没有参数的 PrepareStatement
,如下所示:
You should execute the PrepareStatement
with no parameters as follows:
statement.executeQuery()
调用 executeQuery
使用 String
参数将按原样执行提供的查询(没有绑定参数)。
Calling executeQuery
with a String
parameter will execute the provided query as is (without the bound parameters).
这篇关于正确的语法在'?'附近使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文