gpt4 book ai didi

java - JDBC 给我参数索引超出范围(1 > 参数数量,即 0)

转载 作者:行者123 更新时间:2023-11-30 05:57:18 26 4
gpt4 key购买 nike

获取 Parameter index out of range (1 > number of parameters, which is 0)下面标记的行上有错误。有什么想法吗?

            ...
int hash = ConsistantHash.hash(name);
query = "INSERT INTO `server_info` (`host`, `port, `s_port`, `name`, `hash`) VALUES (?, ?, ?, ?, ?)";

statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, host); //this line
statement.setInt(2, c_port);
statement.setInt(3, s_port);
statement.setString(4, name);
statement.setInt(5, hash);

statement.executeUpdate();
statement.close();

最佳答案

您缺少端口列的匹配转义:

`port

应该是

`port`

关于java - JDBC 给我参数索引超出范围(1 > 参数数量,即 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5891313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com