开发者社区> 问答> 正文

在'?'附近使用正确的语法?mysql

我有一个Java代码:

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:

您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册,以在'?'附近使用正确的语法。

展开
收起
保持可爱mmm 2020-05-17 18:16:23 471 0
1 条回答
写回答
取消 提交回答
  • 您应该执行不PrepareStatement带任何参数的,如下所示:

    statement.executeQuery() executeQuery使用String参数调用将按原样执行提供的查询(没有绑定参数)。来源:stack overflow

    2020-05-17 18:20:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像