身份验证错误:Netbeans中的用户ID或密码无效

时间:2017-10-25 15:34:06

标签: java sql derby

执行程序后出现以下错误

java.sql.SQLNonTransientConnectionException: Connection authentication failure occurred.  Reason: Userid or password invalid.
    at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at sfsfinal.Login.J_LoginActionPerformed(Login.java:481)
    at sfsfinal.Login.access$1200(Login.java:29)
    at sfsfinal.Login$14.actionPerformed(Login.java:366)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: ERROR 08004: Connection authentication failure occurred.  Reason: Userid or password invalid.
    at org.apache.derby.client.net.NetConnection.mapSecchkcd(Unknown Source)
    at org.apache.derby.client.net.NetConnection.securityCheckComplete(Unknown Source)
    at org.apache.derby.client.net.NetConnectionReply.parseSECCHKRM(Unknown Source)
    at org.apache.derby.client.net.NetConnectionReply.parseSECCHKreply(Unknown Source)
    at org.apache.derby.client.net.NetConnectionReply.readSecurityCheck(Unknown Source)
    at org.apache.derby.client.net.NetConnection.readSecurityCheckAndAccessRdb(Unknown Source)
    at org.apache.derby.client.net.NetConnection.flowSecurityCheckAndAccessRdb(Unknown Source)
    at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source)
    at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
    at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
    at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl.newNetConnection(Unknown Source)
    ... 42 more

我的源代码如下:

 private void J_LoginActionPerformed(java.awt.event.ActionEvent evt) {                                        
     Object selected = loginas.getSelectedItem();  
    if(loginas.getSelectedItem().toString().equals("Login As Student")){

    Connection connection;
   PreparedStatement ps = null;
    try {
        int flag=1;
       try {
           Class.forName("com.mysql.jdbc.Driver");
       } catch (Exception ex) {
           System.out.println("Error"+ex);
       }
        connection = DriverManager.getConnection("jdbc:derby://localhost:1527/loginDB","login_user","root");
        Statement st = connection.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM LOGIN_USER.LOGINDETAILS");
        while(rs.next()){
            if(rs.getString(2).equals(jTextField_Username.getText()) && rs.getString(5).equals(new String(pass.getPassword()))){
                flag=0;
                break;
            }}
            if(flag == 0){
                Student_Sfs sfs=new Student_Sfs();
                sfs.setVisible(true);
                sfs.pack();
                sfs.setLocationRelativeTo(null);
                sfs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.dispose();
            }
            else{
               JOptionPane.showMessageDialog(null,"Invalid UserID or Password");
               jTextField_Username.setText(null);
               pass.setText(null);
            }

    } catch (SQLException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }
      }
      else{

    Connection connection;
   PreparedStatement ps = null;
    try {
        int flag=1;
       try {
           Class.forName("com.mysql.jdbc.Driver");
       } catch (Exception ex) {
           System.out.println("Error"+ex);
       }
        connection = DriverManager.getConnection("jdbc:derby://localhost:1527/loginDB","login_user","root");
        Statement st = connection.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM LOGIN_USER.ADMINLOGIN");
        while(rs.next()){
            if(rs.getString(1).equals(jTextField_Username.getText()) && rs.getString(2).equals(new String(pass.getPassword()))){
                flag=0;
                break;
            }}
            if(flag == 0){
                AdminDashboard add=new AdminDashboard();
                add.setVisible(true);
                add.pack();
                add.setLocationRelativeTo(null);
                add.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                this.dispose();
            }
            else{
               JOptionPane.showMessageDialog(null,"Invalid UserID or Password");
               jTextField_Username.setText(null);
               pass.setText(null);
            }

    } catch (SQLException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }

      }
}                                       

请帮忙

0 个答案:

没有答案