SQLException: 没有为参数 9 指定值

SQLException: No value specified for parameter 9

我正在尝试创建一个允许用户创建配置文件的应用程序,但是当我插入数据库时​​出现如上所示的错误。我看过类似的解决方案,但似乎没有任何效果。

目前的相关代码是;

//Invokes myConnection class to link to DB
    Connection con = myConnection.getConnection();
    PreparedStatement ps;

    try 
    {
        //Adds the selected text to DB
        ps = con.prepareStatement("INSERT INTO `user`(`username`, `realname`, `password`, `email`, `gym`, `belt`, `dateofbirth`, `profilepic`, `biography`, `motto`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        ps.setString(1, jTextFieldUsername.getText());
        ps.setString(2, jTextFieldName.getText());
        ps.setString(3, String.valueOf(jPasswordFieldPass.getPassword()));
        ps.setString(4, jTextFieldEmail.getText());
        ps.setString(5, jTextFieldGym.getText());
        ps.setString(6, jComboBoxBelt.toString());
        ps.setDate(7, convertUtilDateToSqlDate(jDateChooserDOB.getDate()));


        InputStream img = new FileInputStream(new File(imagePath));

        ps.setBlob(8, img);

        if(ps.executeUpdate() != 0)
        {
            JOptionPane.showMessageDialog(null, "Account Created!");
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Oops! Something went wrong!");
        }

        ps.setString(9, jTextAreaBiography.getText());
        ps.setString(10, jTextAreaMotto.getText());
    } 
    catch (Exception ex) 
    {
        Logger.getLogger(RegisterPage.class.getName()).log(Level.SEVERE, null, ex);
    }

对不起,如果这是直截了当的,在此先感谢您的帮助!

编辑:回答的很简单,谢天谢地脑洞大开。

你是运行ps.executeUpdate()没有设置参数9和10。

将这些行移到 if(ps.executeUpdate() != 0) 之前:-

ps.setString(9, jTextAreaBiography.getText());
ps.setString(10, jTextAreaMotto.getText());

您的代码中的问题是,

您必须设置参数的所有值,然后使用执行语句。

你的代码应该是这样的。

ps = con.prepareStatement("INSERT INTO `user`(`username`, `realname`, `password`, `email`, `gym`, `belt`, `dateofbirth`, `profilepic`, `biography`, `motto`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setString(1, jTextFieldUsername.getText());
ps.setString(2, jTextFieldName.getText());
ps.setString(3, String.valueOf(jPasswordFieldPass.getPassword()));
ps.setString(4, jTextFieldEmail.getText());
ps.setString(5, jTextFieldGym.getText());
ps.setString(6, jComboBoxBelt.toString());
ps.setDate(7, convertUtilDateToSqlDate(jDateChooserDOB.getDate()));


InputStream img = new FileInputStream(new File(imagePath));
ps.setBlob(8, img);
ps.setString(9, jTextAreaBiography.getText());
ps.setString(10, jTextAreaMotto.getText());

if(ps.executeUpdate() != 0)
{
     JOptionPane.showMessageDialog(null, "Account Created!");
}
 else
{
    JOptionPane.showMessageDialog(null, "Oops! Something went wrong!");
}