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 ]