开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜