繁体   English   中英

java.sql.SQLException:没有为参数 6 指定值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM