0

I am using MySQL and I am getting this error in Eclipse while I am trying to connect my code using JDBC. I am using the version 8.0.20 of workbench

Exception:

Exception in thread "main" java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at com.mysql.cj.jdbc.admin.TimezoneDump.main(TimezoneDump.java:70)

Code snippet

Connection con = null;
try {
    Class.forName("com.mysql.cj.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jamiahamdard", "root", "root");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select * from students");
    while (rs.next())
        System.out.println(rs.getString(1) + " " + rs.getString(2));
} 
catch (SQLException e) {
    System.out.println(e);
}
catch (Exception e) {
    System.out.println(e);
}
finally {
    try {
        con.close();
    } 
    catch (SQLException e) {
        e.printStackTrace();
    }
}

So, can anyone help me out what should I do?

16
  • i am using mysql workbench and i am getting this error in eclipse while i am trying to connect my code using jdbc so can anyone help me out what should i do i am using the version 8.0.20 of workbench Commented May 10, 2020 at 6:32
  • Can you show your code to connect to the database? Commented May 10, 2020 at 6:36
  • yes of course but can you tell what went wrong why i am getting this error? Commented May 10, 2020 at 7:15
  • Connection con = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); con = DriverManage.getConnection("jdbc:mysql://localhost:3306/jamiahamdard", "root", "root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from students"); while (rs.next()) System.out.println(rs.getString(1) + " " + rs.getString(2)); }catch (SQLException e) { System.out.println(e); } catch (Exception e) { System.out.println(e); } finally { try { con.close(); } catch (SQLException e) { e.printStackTrace(); Commented May 10, 2020 at 7:23
  • 1
    @rene thanks the error is solved Commented May 10, 2020 at 9:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.