Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC With MYSQL-Access denied for user 'admin'@'localhost' (using password: YES)

 
prasad kakani
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranch freinds,

I am new to MYSQL.I have coded a simple jdbc program in java to establish a connection with mysql.When i run this program it throws an error like


Error while connecting to databasejava.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)

With this i knew that we should have been granted to access all db in mysql,so i have used this command

mysql>grant all on prasad.* to admin@localhost;
here admin is password and localhost is my machine ip address.

Even i did like this , i am getting same error.Please help in this as soon as possible.Am i doing any wrong..?

Your help would be appreciated.
The code would be like this...

import java.sql.*;

public class ConnectionClass {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
try{
String userName = "admin";
String password = "admin";
String url = "jdbc:mysql://localhost/prasad";
//String query = "Select * FROM prasad.my_table;";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = (Connection)DriverManager.getConnection (url, userName, password);
System.out.println("Connection has been established");
}catch(Exception e){
System.out.println("Error while connecting to database"+e);
}
finally{
if(conn!=null){
try
{
conn.close();
System.out.println ("Database connection terminated");
}
catch (SQLException e)
{
System.out.println ("Error while terminatig the connection the database");
}
}
}
}

}



Thanks
Venkat.
[ November 18, 2008: Message edited by: prasad kakani ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you passing the credentials you think you are when you get your connection? Always worth checking.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mysql>grant all on prasad.* to admin@localhost;
here admin is password and localhost is my machine ip address.


Does this mean you really did something like:

grant all on prasad.* to admin@192.168.1.100;

If so, try changing this line of code as follows:

String url = "jdbc:mysql://192.168.1.100/prasad";
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic