在 '?' 附近使用正确的语法 [英] 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()
使用 String
参数调用 executeQuery
将按原样执行提供的查询(不带绑定参数).
Calling executeQuery
with a String
parameter will execute the provided query as is (without the bound parameters).
这篇关于在 '?' 附近使用正确的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文