JDBC giving me Parameter index out of range (1 > number of parameters, which is 0) [duplicate]
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`
精彩评论