[英]java.sql.SQLException :no value specified for parameter 6
當按下更新按鈕時,它顯示:
“java.sql.SQLException:參數超出范圍(1>參數數量,為0)”。
private void updateActionPerformed(java.awt.event.ActionEvent evt) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/smakdb","root","kisal400");
String sql="Update itemk set name=?,type=?, buying price=?, selling price=?,description=? where itemid=?";
pst=conn.prepareStatement(sql);
pst.setString(1, name2.getText());
String value=type2.getSelectedItem().toString();
pst.setString(2,value);
pst.setDouble(3,Double.parseDouble(buying2.getText()));
pst.setDouble(4,Double.parseDouble(selling2.getText()));
pst.setString(5,descript2.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "updated!!!");
conn.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
查詢中有6個問號,為什么不設置第6個參數值?
您還需要設置itemid
。
在 String sql 中,您有六個參數“?” 並一次設置五個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.