-2

I am beginner of java and this is the change password coding.I tried to use update query to update the password.But something wrong with my coding.Can someone help me to find it out? After i execute, occur the error:

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();

        }

}
Ben Steffan
  • 1,015
  • 11
  • 16
areil
  • 3
  • 3
  • What have you tried so far to pinpoint the error? What do you think is wrong? Please show what you have tried so far! – Ben Steffan Apr 24 '17 at 16:10
  • Hi, thanks for reply.I'm trying to execute a prepared statement in JDBC, and everytime I execute it I get the error message "Paramater not set". – areil Apr 25 '17 at 04:49

1 Answers1

1

You have three ? but only two parameter setup. You are missing the third parameter.

 st.setString(3, userId);
yogidilip
  • 782
  • 5
  • 18