为什么java抛出参数索引超出范围SQLerror

时间:2014-10-03 08:00:07

标签: java mysql sql bukkit sqlexception

我多次运行此代码并且java不断抛出java.sql.SQLException参数索引超出范围(1>参数个数为0),我认为它在SELECT * FROM上有错误CARD查询,我在这里做错了什么?

@EventHandler
public void onJoin(PlayerJoinEvent event){
    Player player = event.getPlayer();
    openConnection();
    try{
        PreparedStatement sql = connection.prepareStatement("SELECT * FROM `Cards` WHERE `UUID`=?;");
        sql.setString(1, player.getUniqueId().toString());
        ResultSet rs = sql.executeQuery();
        if(!rs.next()){
            PreparedStatement sql1 = connection.prepareStatement("INSET INTO `Cards` (`UUID`, `username`, `name`, `race`, `tribe`, `gender`, age`, `desc`, `channel`, `ooc`) VALUES(?,?,?,?,?,?,?,?,?,?);");
            sql1.setString(1, player.getUniqueId().toString());
            sql1.setString(2, player.getName());
            sql1.setString(3, "NONE");
            sql1.setString(4, "NONE");
            sql1.setString(5, "NONE");
            sql1.setString(6, "NONE");
            sql1.setString(7, "0");
            sql1.setString(8, "NONE");
            sql1.setString(9, "RP");
            sql1.setString(10, "1");
            sql1.execute();
            sql1.close();
        }
    }catch(SQLException e){
        e.printStackTrace();
    }finally{
        closeConnection();
    }
}

1 个答案:

答案 0 :(得分:5)

(`UUID`, `username`, `name`, `race`, `tribe`, `gender`, age`, `desc`, `channel

age上缺少引号?