更新MySQL:java.sql.SQLException:未为参数8指定值 [英] Update MySQL: java.sql.SQLException: No value specified for parameter 8

查看:107
本文介绍了更新MySQL:java.sql.SQLException:未为参数8指定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我在这里缺少什么,但似乎对我没有任何帮助.我尝试了几种方法,但似乎都没有效果.任何的想法?

Not to sure what I am missing here but nothing seems to be working for me. I tried several approaches and none seemed to work. Any idea?

这是我的代码:

btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        String pid = textIDField.getText();
        String fn = textFNameField.getText();
        String ln = textLNameField.getText();
        String add = addressField.getText();
        String city = cityField.getText();
        String phone = phoneField.getText();
        String mid = medIDField.getText();

        try{
            Connection conn = DriverManager.getConnection("dbinfo");
            String query = "UPDATE Patient SET PatID=?,FirstName=?,LastName=?,Address=?,City=?,Phone=?,MedID=? WHERE PatID=? AND MedID=?";

            PreparedStatement pst = conn.prepareStatement(query);
            pst.setString(1, pid);
            pst.setString(2, fn );
            pst.setString(3, ln );
            pst.setString(4, add );
            pst.setString(5, city );
            pst.setString(6, phone );
            pst.setString(7, mid );

            pst.executeUpdate();
            JOptionPane.showMessageDialog(null, "Patient Updated");
            pst.close();

        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
});

推荐答案

请注意,您尚未设置最后两个参数的值,因此请在下面进行检查

please you have not set the values for the last two parameter so check below

 try{
                Connection conn = DriverManager.getConnection("dbinfo");
                String query = "UPDATE Patient SET  
          PatID=?,FirstName=?,LastName=?,Address=?,City=?,Phone=?,MedID=? ` `WHERE PatID=? AND MedID=?";

                PreparedStatement pst = conn.prepareStatement(query);
                pst.setString(1, pid);
                pst.setString(2, fn );
                pst.setString(3, ln );
                pst.setString(4, add );
                pst.setString(5, city );
                pst.setString(6, phone );
                pst.setString(7, mid );
                 pst.setString(8, mid );//this last two
                pst.setString(9, pid);

                pst.executeUpdate();
                JOptionPane.showMessageDialog(null, "Patient Updated");
                pst.close();

            }catch(Exception ex){
                ex.printStackTrace();
            }

这篇关于更新MySQL:java.sql.SQLException:未为参数8指定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆