【问题标题】:Select count(*) from people where id =?;从 id =?; 的人中选择 count(*)
【发布时间】:2021-02-08 04:20:34
【问题描述】:

使用 MacOS - Java - MySql 8.0 - jdbc 8.0 - Intellij。

当我运行 this (Select count(*) from people where id =?;) 替换 ?使用数字 1 可以正常工作。但是当我这样做时:

for (Person person: people) {
            int id = person.getId();

checkStmt.setInt(1, id);
            
ResultSet checkResult = checkStmt.executeQuery(checkSql);

我明白了:

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 '?' at line 1

运行调试器,数组返回的id值为1。

【问题讨论】:

    标签: java mysql intellij-idea


    【解决方案1】:

    您已经调用了setInt,然后使用不同的查询将其丢弃。改变

    checkStmt.setInt(1, id);
    ResultSet checkResult = checkStmt.executeQuery(checkSql);
    

    checkStmt.setInt(1, id);
    ResultSet checkResult = checkStmt.executeQuery();
    

    【讨论】:

    • 非常感谢,我知道我脑子里放了个屁,但就是无法消除迷雾。
    猜你喜欢
    • 2023-03-19
    • 2017-09-15
    • 1970-01-01
    • 2013-03-20
    • 2010-10-11
    • 2013-02-02
    • 2011-10-17
    • 1970-01-01
    • 2014-05-22
    相关资源
    最近更新 更多