Forums Register Login

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

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Are you passing the credentials you think you are when you get your connection? Always worth checking.
+Pie Number of slices to send: Send
 

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";
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7360 times.
Similar Threads
i couldn't run jdbc progam in netbeans
how to connect MS Access directly
java.sql.SQLException Access Denied
Problem with com.mysql.jdbc.Driver driver
strange problem when accessing MySQL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:31:41.