0

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)
6
  • Do you think all that code is relevant? Have you look up the error on the internet (or even this site)? I see a huge lack of effort. Commented Mar 15, 2014 at 0:26
  • i thought it would help to know the whole class. sorry Commented Mar 15, 2014 at 0:28
  • As Sotirios Delimanolis said, please make your code more concise and isolate the issue. Then it will be easier for us to help you. Commented Mar 15, 2014 at 0:29
  • 2
    have you tried to set the password for both yerobot@localhost and yerobot@'%' ? Because MySQL differentiates local access and remote access passwords.. Commented Mar 15, 2014 at 0:32
  • Well thank you Yudhi. setting up the user again with @localhost does work. i get now table xyz doesnt exist errors but ican work with that ow since connecting works. thanks ! Commented Mar 15, 2014 at 0:40

2 Answers 2

1

You need to set the password for both yerobot@localhost and yerobot@'%'

MySQL differentiates local access and remote access passwords.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.