我的更新查询有什么问题,参数未设置错误

时间:2017-04-24 16:05:29

标签: java ucanaccess

我是java的初学者,这是更改密码编码。我试图使用更新查询来更新密码。但是我的编码有问题。有人帮我找到它吗?执行后,发生错误:

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.1 Parameter not set
    at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:256)
    at UserPassword.actionPerformed(UserPassword.java:142)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLException: Parameter not set
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.checkParametersSet(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
    at net.ucanaccess.jdbc.ExecuteUpdate.executeWrapped(ExecuteUpdate.java:65)
    at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:208)
    at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:50)
    at net.ucanaccess.jdbc.UcanaccessPreparedStatement.executeUpdate(UcanaccessPreparedStatement.java:253)
    ... 37 more
Caused by: org.hsqldb.HsqlException: Parameter not set
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    ... 45 more
public void actionPerformed(ActionEvent action) 
    {

        if(action.getSource() == backButton)
        {
            dispose();
        }

        String userName = field1.getText();
        char [] s1 = field2.getPassword(); 
        char [] s2 = field3.getPassword(); 

        String userpass = new String(s1);   
        String userpass2 = new String(s2);

            try
            {
                String UpdateQuery = null;
                PreparedStatement st = null;

                Connection connect = DriverManager.getConnection("jdbc:ucanaccess://Database.accdb");

                if(action.getSource() == changeButton)
                {
                    UpdateQuery = "UPDATE STUDENT SET StudentID = ?, Password = ? WHERE StudentID = ?";
                    st = connect.prepareStatement(UpdateQuery);

                    if(userpass.equals(userpass2))
                    {
                                st.setString(1, userName);
                                st.setString(2, userpass2); 

                                st.executeUpdate();

                                JOptionPane.showMessageDialog(this,"Username and Password changed!","Student",JOptionPane.INFORMATION_MESSAGE);
                                dispose();
                                UserPage up = new UserPage(null);

                                connect.close();

                    }   


                        else if(userpass != userpass2)
                        {
                            JOptionPane.showMessageDialog(this,"Password not match!","Password error",JOptionPane.ERROR_MESSAGE);
                        }
                }


            }
            catch (SQLException e1)
            {
                e1.printStackTrace();
            }
                reset();

        }

}

1 个答案:

答案 0 :(得分:1)

你有三个吗?但只有两个参数设置。您缺少第三个参数。

 st.setString(3, userId);