This question already has answers here:
java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) [closed]
                                
                                    (2个答案)
                                
                        
                                3年前关闭。
            
                    
在下面标记的行上出现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/

10-13 09:08