I am simply trying to get a java class to connect to the MySQL server running locally on the same machine. My code is as follows:
import java.sql.*;
public class CatalogGUI
{
private Connection conn;
String dbname = "dreamteam";
String username = "root@%";
String dbpasswd = "*********";
public DBClassName()
{
try{ Class.forName("org.gjt.mm.mysql.Driver"); }
catch(Exception e)
{
System.err.println("Unable to load driver.");
System.exit(1);
}
try{conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/"+dbname+"?user="+username+"&password="+dbpasswd);}
catch(SQLException e)
{
System.out.println("Unable to connect: "+e);
System.exit(1);
}
}
}
When I run it, I get
"Unable to connect: Java.sql.SQLException: Invalid authorizaiton specification: Access denied for user 'root@localhost'@'localhost' (using password: YES)"
In the users table in the 'mysql' database, the 'host' field for 'root' is set to %, which means 'root' should be able to connect from anywhere(the ultimate goal in what I'm doing is to connect remotely, but for now let's just focus on getting to connect locally).
I tried connecting with and without the password, neither worked.
I tried changing the username variable to just "root" istead of "root@%", but then I got a different error:
"Unable to connect: Java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?"
I don't know WHAT that's about. And yes, the mysql server is running on this local machine. If it wasn't, I wouldn't have even gotten as far as the 'Invalid Authorizaiton Specification' error before.
I don't know what to do. I am at a loss.
Edited by: namkcuR on Feb 27, 2008 9:16 PM