• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you passing the credentials you think you are when you get your connection? Always worth checking.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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";
 
reply
    Bookmark Topic Watch Topic
  • New Topic