开发者

JDBC giving me Parameter index out of range (1 > number of parameters, which is 0) [duplicate]

开发者 https://www.devze.com 2023-03-02 18:07 出处:网络
This question already has answers here: java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed]
This question already has answers here: java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed] (2 answers) Closed 6 years ago.

Get开发者_如何学运维ting Parameter index out of range (1 > number of parameters, which is 0) error on the line that is marked below. Any ideas?

            ...
            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();


You are missing a matching escape of the port column:

`port

Should be

`port`
0

精彩评论

暂无评论...
验证码 换一张
取 消