Reputation: 371
I'm not able to connect to the Database but I don't know why, since the username and password are correct and I'm able to connect through phpmyadmin locally.
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager.getConnection(
"jdbc:mysql://localhost/yerobot", "yerobot", "yerobot123");
preparedStatement = connect.prepareStatement("select * from userdata");
resultSet = preparedStatement.executeQuery();
while(resultSet.next()){
// do read rs
}
Whenever I call for a connection, I get this stacktrace:
java.sql.SQLException: Access denied for user 'yerobot'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2535)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2320)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at yerobot.MySQLAccess.setZockerzaster(MySQLAccess.java:92)
at yerobot.MyBot.zasterAction(MyBot.java:102)
at yerobot.MyBot$1.run(MyBot.java:94)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Upvotes: 0
Views: 1986
Reputation: 1704
You need to set the password for both yerobot@localhost and yerobot@'%'
MySQL differentiates local access and remote access passwords.
Upvotes: 1
Reputation: 310860
You got the username or password wrong, or it isn't authorised to connect from localhost. Simple as that. And perfectly clear from the exception.
Upvotes: 0