0

I´m using eclipse and want to connect to my mysql database. I am new to SQL and thats my first time I want to do something like this. I´ve created two methods, which should connect to a mysql database, which is running on my PC. The first method should create a connection :

public static Connection connectionSQL() {
    try {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/example"; 

        String username = "example";
        String password = "1111";
        Class.forName(driver);

        Connection connection = DriverManager.getConnection(url, username, password);
        System.out.println("Connected!");

    } catch(SQLException | ClassNotFoundException e) {
        System.out.println("ERROR: Cant connect to database! "+ e);
    }
    return null; 
}

the second should create a table :

    public static void createTable() {
    try {
        Connection connection = connectionSQL();
        PreparedStatement ps = connection.prepareStatement("CREATE TABLE IF NOT EXISTS scammerjail(id int NOT NULL AUTO_INCREMENT, Username String, Countdown int, PRIMARY KEY(id))");
        ps.executeUpdate();

    } catch(SQLException e) {
        System.out.println("ERROR: Cant create Table! " + e);
    }
    finally {
        System.out.println("Table created!");
    }
}

But everytime I try to run my Code, I get the following message:

 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client

I´m using maven as build tool and my dependency and its version isnt wrong I think.

Mx1co
  • 9
  • 1
  • 6
  • Can you [Refer](https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server) here and check if that works? – Govind Jun 07 '20 at 16:34
  • Hello, have you checked the answers to similar problems: [answer 1](https://stackoverflow.com/questions/50505042/mysqlnontransientconnectionexception-client-does-not-support-authentication-pro), [answer 2](https://stackoverflow.com/questions/50424900/error-client-does-not-support-authentication-protocol-requested-by-server-cons)? Please also note that you will get `NullPointerException` as soon as you resolve the mentioned problem, because you return null in `connectionSQL`. – Nowhere Man Jun 07 '20 at 16:35
  • @AlexRudenko fixed that, thanks ! But I´m using version 8.0.20 in my dependency and my MySQL Workbench, which I downloaded today is on the same version. – Mx1co Jun 07 '20 at 16:46

0 Answers0