首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更新MySQL: java.sql.SQLException:没有为参数8指定值

更新MySQL: java.sql.SQLException:没有为参数8指定值
EN

Stack Overflow用户
提问于 2016-05-03 21:37:29
回答 1查看 4.3K关注 0票数 0

不确定我在这里错过了什么,但似乎没有什么对我有帮助。我尝试了几种方法,但似乎都没有用。有什么想法吗?

这是我的密码:

代码语言:javascript
运行
复制
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();
        }
    }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-03 21:49:45

请您没有为最后两个参数设置值,所以请检查下面

代码语言:javascript
运行
复制
 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();
            }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37014817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档