0

I am trying jdbc connection with mysql but getting SQLException.

My code is:--

public void createConn() throws MysqlException {

    try {
                String url ="jdbc:mysql://172.168.1.73:3306/mysql";
                Connection con =DriverManager.getConnection(url,"root", "");
                System.out.println("URL: " + url);
                System.out.println("Connection: " + con);
        }

i am getting following exception...

java.sql.SQLException: Access denied for user 'root'@'192.168.1.187' (using password: NO)

I am trying to connect to 172.168.1.73 but it is trying to coonect to 192.168.1.187...

root user doesnt have any password.

Please tell me how can i solve this issue.

1
  • What is your database schema name? Is it mysql? Commented Jan 5, 2012 at 4:12

2 Answers 2

2

Check whether root user can access the machine with IP 192.168.1.187

It is not trying to connect to 192.168.1.187.

'root'@'192.168.1.187' in the exception means a user with user name "root" in the machine with IP '192.168.1.187' trying to access the database server. Therefore 192.168.1.187 is the client IP.

Database servers restricts the access based on user and the IP of the machine user use to connect. Therefore if you want to connect to the database server from a IP '192.168.1.187', you should grant permission to access the user to access from that specific IP.

Check MySQL GRANT for more details.

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

4 Comments

Exactly what I was thinking. +1.
thanks for the help...its working now. root doesnt have access to 192.168.1.187 IP...
I wanted to know how can i get to know that which database is accessible to which user????
In mysql database server, there is a schema named "mysql". In that schema, there is a table named "User". You can find the mysql user details and granted permissions in that table. and see the "db" table for database specific users and user privileges. Please note that "%" in "host" field means that user can access from any IP.
0

To be more secure, you need to assign the root password and try it again. The page below contains Java code to connect to mysql database: http://www.worldbestlearningcenter.com/index_files/java_database_connect_mysql.htm

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.