0

I am trying to make mysql database connection from my war file using jdbc connection string as shown below:-

    String connectionURL = "jdbc:mysql://localhost:3306/DatabaseName? user=DatabaseUserName;password=DatabasePassword";

Now my war file and database both available on server, & i am doing my execution from server itself. But the problem is that i am getting below error which says:-

    INFO: java.sql.SQLException: Access denied for user 'grandsho_root;password=pwd'@'localhost' (using password: NO)

where

grandsho_root is my user, pwd is my password ...I need to know what exactly is this problem? Do i need to perform GRANT ALL command. or something like that?

puneetjava
  • 167
  • 3
  • 7
  • 20
  • Try to grant all privileges to user grandsho_root. Should work. – user2339071 Aug 23 '13 at 06:45
  • @user2339071 i have done that? – puneetjava Aug 23 '13 at 06:46
  • It's not a GRANT issue. The user credentials are not known. There are 3 parts to the credentials: username, password, hostname. Make sure there is actually a user called grand_sho with your password that is allowed to connect from localhost. – Xabster Aug 23 '13 at 06:47
  • have a look here maybe: http://stackoverflow.com/questions/1457716/what-is-the-mysql-jdbc-driver-connection-string – Matthias Aug 23 '13 at 06:49
  • @Xabster is my connection string correct which is mentioned in my question? i have created user for that database, but as you said make sure user with password allowed to connect? how to do this step on my server? – puneetjava Aug 23 '13 at 06:51
  • please use DriverManager.getConnection(String url, String user, String password) instead of DriverManager.getConnection(String url) – shola Aug 23 '13 at 07:03
  • @user2656285: no, there's indeed something wrong with how you're trying it. The error says that it did not receive a password. Use DriverManager.getConnection(url, username, password) like the guy above said. – Xabster Aug 23 '13 at 07:12
  • @shola thanks i've tried this earlier, but will try again now – puneetjava Aug 23 '13 at 07:13

1 Answers1

0

When you get the message "(using password: NO)" this means you were trying to connect without a password set. The log message tells you that the user "grandsho_root;password=pwd" is not allowed to connect. This means your connection string is wrong because you use ; to separate your parameters instead of a &. This is how your connection string should look:

jdbc:mysql://localhost:3306/DatabaseName?user=sqluser&password=sqluserpw

When you still have problems please check if your user is set up correctly. Check that grandsho_root has a password set, that he is allowed to connect from localhost and you granted the necessary privileges to your schema.

Also check the MySQL documentation here

mithrandir
  • 738
  • 1
  • 6
  • 17
  • how to make sure that my user is allowed to connect from localhost? – puneetjava Aug 23 '13 at 07:29
  • via command line you can check which host is allowed for your user with: "use mysql; select user, host from user;" You can add entries the users table or update it as you want. But be sure to fire a "flush privileges;" afterwards. – mithrandir Aug 23 '13 at 09:10