Eclipse:java.sql.SQLException:用户'root'@'localhost'的访问被拒绝(使用密码:是)

时间:2019-10-08 01:42:44

标签: java mysql database jdbc dbconnection

这个问题已经被问过了,但是没有一个解决方案对我有用。我收到以下错误

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

当我执行以下代码时

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;



public class MyFirstDBConn {
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost/repository";

//  Database credentials
   static final String USER = "root";
   static final String PASS = "pass";

    public static void main(String[] args) {

        try{
            System.out.println("Register the DriverManager with DB driver");


            Class.forName(JDBC_DRIVER );    

            Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

            Statement statement = conn.createStatement();

            ......
            }
    }
}

请帮助。

0 个答案:

没有答案