Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java NetBeans表示,用户';根'@';本地主机';(使用密码:是)_Java_Mysql_Database Design_Sqlexception - Fatal编程技术网

Java NetBeans表示,用户';根'@';本地主机';(使用密码:是)

Java NetBeans表示,用户';根'@';本地主机';(使用密码:是),java,mysql,database-design,sqlexception,Java,Mysql,Database Design,Sqlexception,我是java和开发的新手。我正在使用NetBeans 8.0和查询浏览器1.1.2创建数据库和表。一旦我在输入用户详细信息后点击登录按钮,就会显示一条消息,如下所示 java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) 我使用querybrowser创建了数据库,因为我对MYSQL工作台比对querybrowser还不熟悉 以下是主页代码 public class Home_

我是java和开发的新手。我正在使用NetBeans 8.0和查询浏览器1.1.2创建数据库和表。一旦我在输入用户详细信息后点击登录按钮,就会显示一条消息,如下所示

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
我使用querybrowser创建了数据库,因为我对MYSQL工作台比对querybrowser还不熟悉

以下是主页代码

public class Home_Page extends javax.swing.JFrame {

    public String User;
    Model.JDBC j=new JDBC();

    public Home_Page(String U_ID) {
        initComponents();

        User=U_ID; 
        Toolkit t = Toolkit.getDefaultToolkit();
        Dimension d = t.getScreenSize();
        int w = (int) d.getWidth();
        int h = (int) d.getHeight()-40;
        setBounds(0, 0, w, h);
        jLabel2.setText(new Controler.getDate().date());
        time();
        jLabel3.setText(U_ID);
        ResultSet rs;

        try {

          rs = j.getData("select ulevel from user U_ID='"+U_ID+"'");  

          if(rs.next()==true){

                  if(rs.getString(1).equals("Admin")){

                    home.setEnabled(true);
                    EMPLOYEE.setEnabled(true);
                    employee.setEnabled(true);
                    user.setEnabled(true);
                    machine.setEnabled(true);
                    branch.setEnabled(true);

                }else if(rs.getString(1).equals("user")){


                    home.setEnabled(true);                  
                    EMPLOYEE.setEnabled(false);
                    employee.setEnabled(false);
                    user.setEnabled(false);
                    machine.setEnabled(false);
                    branch.setEnabled(false);


                }else{
                     System.out.println("else");

                }
           }

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

    }

          public  void time() {
        new Thread(new Runnable() {

            public  void run() {
                while (true) {
                    String times = new Date().toString();
                    String h = times.split(" ")[3];
                    jLabel1.setText(h);
                    try {
                        Thread.sleep(60);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

        @SuppressWarnings("unchecked")

    private void branchActionPerformed(java.awt.event.ActionEvent evt) {                                       

        jDesktopPane1.removeAll();
        Branch b=new Branch();
        jDesktopPane1.add(b);
        b.setVisible(true);
        jDesktopPane1.updateUI();
// TODO add your handling code here:
    }                                      
 public void clear() {

    this.dispose();

    }
    private void logoutActionPerformed(java.awt.event.ActionEvent evt) {                                       

      java.awt.Toolkit.getDefaultToolkit().beep();  int t = JOptionPane.showConfirmDialog(null, "Are You Sure...?");
                        if(t==JOptionPane.YES_OPTION){
                           this.dispose();
                            clear();
                            new Viewer.login().setVisible(true);
                        }
                        else if(t==JOptionPane.NO_OPTION)
                        {


                        }
                        else
                        {

                        }
    }                                      

    private void userActionPerformed(java.awt.event.ActionEvent evt) {                                     

        jDesktopPane1.removeAll();       
        User_ u=new User_();
        jDesktopPane1.add(u);
        u.setVisible(true);
        jDesktopPane1.updateUI();
// TODO add your handling code here:
    }                                    

    private void employeeActionPerformed(java.awt.event.ActionEvent evt) {                                         

        jDesktopPane1.removeAll();
        Employee_ emp=new Employee_();
        jDesktopPane1.add(emp);
        emp.setVisible(true);
        jDesktopPane1.updateUI();
        // TODO add your handling code here:
    }                                        

    private void machineActionPerformed(java.awt.event.ActionEvent evt) {                                        

        jDesktopPane1.removeAll();
        machine_ m = new machine_();
        jDesktopPane1.add(m);
        m.setVisible(true);
        jDesktopPane1.updateUI();                            
// TODO add your handling code here:
    }                                       

    private void homeActionPerformed(java.awt.event.ActionEvent evt) {                                     


        // TODO add your handling code here:
    }                                    

    private void EMPLOYEEActionPerformed(java.awt.event.ActionEvent evt) {                                         


// TODO add your handling code here:
    }                                        

    public static void main(String args[]) {


        Calendar expiry = Calendar.getInstance();
        expiry.set(2013, 9 , 27,0,0); // Expire at 31 Jan 2010
        Calendar now = Calendar.getInstance();
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Home_Page(" ").setVisible(true);
            }
        });
    }
}

下面是我的登录表单代码

public class login extends javax.swing.JFrame {

    public login() {
        initComponents();
    }

    @SuppressWarnings("unchecked")

    private void loginActionPerformed(java.awt.event.ActionEvent evt) {                                      

        if (eid.getText().trim().length() == 0 | pwd.getPassword() == null) {
            JOptionPane.showMessageDialog(null, "Username or Password cannot be blank", "Error", 0);
        } else {
            try {
                ResultSet rs = new DBG1().getData("select * from user where eid = '" +eid.getText() + "'");
                Vector v = new Vector();
                if (rs.next()) {
                    v.add(rs.getString(1));
                }
                if (v.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
                    eid.setText("");
                    pwd.setText("");
                    eid.grabFocus();
                } else {
                    ResultSet rs1 = new DBG1().getData("select * from user where eid ='" + eid.getText() + "'");
                    while (rs1.next()) {
                        String type = (rs1.getString(3));

                        if (eid.getText().trim().equalsIgnoreCase(rs1.getString("eid")) && pwd.getText().equals(rs1.getString("pwd")) && type.equals("Admin")) {
                            this.dispose();
                           new Home_Page(eid.getText()).setVisible(true);
                          //  new Home_Page(eid.getText()).setVisible(true);
                        } else if (eid.getText().trim().equalsIgnoreCase(rs1.getString("eid")) && pwd.getText().equals(rs1.getString("pwd")) && type.equals("user")) {
                            this.dispose();
                           new Home_Page(eid.getText()).setVisible(true);

                        } 
                        else {
                            JOptionPane.showMessageDialog(null, "Invalid Username or Password", "Error", 0);
                            eid.setText("");
                            pwd.setText("");
                            eid.grabFocus();
                        }
                    }
                    this.dispose();
                  }
            } catch (Exception e) {
                System.out.println(e);
            }
        }
// TODO add your handling code here:
    }                                     

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {                                       

       new login().dispose();
       System.out.println(pwd.getPassword());

        System.out.println("Cleared");
        this.dispose();
        // TODO add your handling code here:
    }                                      

    private void eidActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add your handling code here:
    }                                   


    public static void main(String args[]) {

               java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                new Viewer.login().setVisible(true);
            }
        });
    }

}
当我调试项目时,它应该首先运行一个加载窗口(此处不包括该窗口),然后运行登录窗口。一旦我输入详细信息并按下登录按钮,上面的错误将显示在“POST_NEW debug panel”中
我已经研究并遵循了本网站先前发布的所有类似类型问题中提到的所有说明。但我现在处于这种状况。请任何人指出我应该在哪里修改代码,或者如何消除此错误,并进入我的项目主页

确保您的数据库名为“root”数据库的密码是否为空…请正确设置数据库身份验证以进行授权。

尝试使用用户名root和密码empty。如果这不起作用,你可以试试这个:

最后我可以解决它。:) 发生的事情是,我给了“root”用户名的密码“root”。当我将密码更改为“root”时,即使出现另一个错误,我也可以向前一步。我现在正在做。 再次非常感谢大家。:)

下面是代码

public Connection getCon() throws Exception{
        String driver ="com.mysql.jdbc.Driver";
        String url="jdbc:mysql://localhost:3306/FINAL_POST?useUnicode=true&ampcharacterEncoding=UTF-8";
        Class.forName(driver);
        Connection con=DriverManager.getConnection(url, "root", "root");
        return con;
    }

以管理员身份运行Netbeans,因为Netbeans在当前用户Preveligus中不是mysql,
谢谢

注意:这与IDE或Swing无关,而与
SQLException
有关。更改标记以反映问题。您应该显示用于连接数据库的代码。与使用
root
用户(默认情况下)相比,最好创建另一个用户。那么我可以编辑帖子吗?现在删除上面的代码并放入数据库连接代码可以吗?谢谢大家!问题解决了。当我使用“root”作为密码时,它起了作用。谢谢你,巴鲁。。我试试看:)也没用。但我找到了解决办法。当我把root作为密码时,它是如何工作的。谢谢你,格林伍兹先生。问题解决了。我使用“root”作为密码。然后它成功了。