java.sql.SQLException:没有为参数6指定值
按下更新按钮时,显示: “java.sql.SQLException:参数超出范围(1>参数数量,即0)”java.sql.SQLException:没有为参数6指定值,java,netbeans,Java,Netbeans,按下更新按钮时,显示: “java.sql.SQLException:参数超出范围(1>参数数量,即0)” 查询中有6个问号,为什么不设置第6个参数值 您还需要设置itemid。在字符串sql中,您有六个参数“”,一旦设置了五个参数。编辑。现在它显示“java.sql.SQLSyntaxErrorException.You have error In your sql syntax.”编辑。现在它显示“java.sql.SQLSyntaxErrorException.You have error
查询中有6个问号,为什么不设置第6个参数值
您还需要设置
itemid
。在字符串sql中,您有六个参数“”,一旦设置了五个参数。编辑。现在它显示“java.sql.SQLSyntaxErrorException.You have error In your sql syntax.”编辑。现在它显示“java.sql.SQLSyntaxErrorException.You have error In your sql syntax.”当然,它是错误的<代码>更新itemk集合名称=?,类型=?,购买价格=?,销售价格=?,说明=?其中itemid=?您试图说的是购买价格
和出售价格
对吗?@kisalriff别忘了选择我的作为答案:)您的SQL似乎包含带有空格的列名(例如购买价格)。即使这是允许的,也不推荐这样做。您可能需要在SQL中的这些列名周围加引号…没有为参数6指定值
-消息很清楚,您需要指定第6个参数itemid
的可能重复项
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);
}