JDBC给我参数索引超出范围(1>参数个数,为0)

时间:2011-05-05 00:17:49

标签: java jdbc

在下面标记的行上出现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();

1 个答案:

答案 0 :(得分:6)

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

`port

应该是

`port`