简体   繁体   中英

Access denied connecting from java to mysql

I'm trying connect to database from java and get the following error message:

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

but using same credentials from command line I'm connect

server$ mysql -ugda -pgda
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2666453
Server version: 5.5.39-36.0-log Percona Server (GPL), Release 36.0, Revision 697

Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

on another database my java work fine and able connect. seems to be an issue at database level ?! what I need to fix at database level ?

adding the code of the connection:

public Connection getConnection() {     
    try {
        Class.forName(jdbcDriver);

        connection = DriverManager.getConnection(connectionString());
    }
    catch(Exception ex) {
        ex.printStackTrace();
        logger.error("Exception:" + ex.getMessage());
        errorMessage = ex.getMessage();
    }

    return connection;
}

where:

jdbc:mysql://127.0.0.1:3306/db?user=gda&password=gda

Try to pass the username and password in this manner:

String DB_URL = "jdbc:mysql://localhost/xyz";
String USER = "username";
String PASS = "password";

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

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