简体   繁体   中英

MySQL and JDBC Error Logging In

I've been messing around with JDBC and trying to connect to a test database that I've created, however I keep getting this error:

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

I'm not sure how to fix this, I've tried two variations of my code both throwing back the same error here they are:

    public static void main(String[] args){
       Connection connection = null;
       Statement statement = null;
       try{
           Class.forName("com.mysql.jdbc.Driver");
           connection = DriverManager.getConnection("jdbc:mysql://localhost/feedback?   user=root&password=1234");
           System.out.print("Connected");
           connection.close();
           System.out.println("Closed");
       }catch(Exception e){
           System.out.println("Error: " + e);
       }
   }

As well as:

public class JDBC {
public static void main(String[] args) throws SQLException {
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/test";
    String user = "root";
    String password = "1234";
    System.setProperty(driver, "");

    try {
        DriverManager.getConnection(url,user,password);
    } catch (SQLException e) {
        System.out.println("Error: " + e);
    }
  }
}

Can anyone give me a pointer on where to go on from here?

Message is pretty much descriptive, it seems either userID, password (or) combination of both are not matching

EDIT:

After screenshot issue is related to wrong port definition in program.

Try this -

  1. Reset password of root. Check your connection URL.
  2. If #1 does not work then instead of using root, create new user with full access rights.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM