This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes JDBC With MYSQL-Access denied for user 'admin'@'localhost' (using password: YES) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC With MYSQL-Access denied for user Watch "JDBC With MYSQL-Access denied for user New topic
Author

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

prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59
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

Joined: Apr 14, 2004
Posts: 10336

Are you passing the credentials you think you are when you get your connection? Always worth checking.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

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";


JBoss In Action
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JDBC With MYSQL-Access denied for user 'admin'@'localhost' (using password: YES)
 
Similar Threads
Problem with com.mysql.jdbc.Driver driver
java.sql.SQLException Access Denied
how to connect MS Access directly
i couldn't run jdbc progam in netbeans
strange problem when accessing MySQL