java - SQLException: 没有为参数 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());
推荐阅读
- powerbi - 通过 PowerApps 和 PowerBI 管理需求摄入列表
- python - 是否可以在 Pydantic 中将未知字段更改为 camelCase?
- node.js - 如何在 typeorm 中将默认日期格式更改为 dd/mm/yyyy?
- tableau-api - Tableau 使用多个 LOD
- java - 缓冲区紧凑 API
- r - 如何让 readxl::read_xls 正确读取该数据集的第一列?
- sql-server - 关系模式是否应该像 sql-server 中的表
- c# - 如何在 C# 中构建复合表达式?
- php - PDO json_decode 在进入类之前
- r - 负二项式回归中尺度连续变量的非尺度系数