C
coglethorpe
Guest
I'm trying to connect to a MySQL database I set up with Plesk from Java. I'm running the Java code on the same machine as the server, but I still get an exception. The sample code and exceptions are below. Is there a different URL I should use to connect to? I have verified the username and password from the command line.
The exception occurs in the call to "DriverManager.getConnection".
Any help is appreciated....
--------The Exception-------
java.sql.SQLException: Invalid authorization specification, message from server : "Access denied for user: 'myuser@VirtualServerName' (Using password: YES)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1752)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:833)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1734)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java :361)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DBTester.main(DBTester.java:23)
---------The Code------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBTester
{
public static void main(String[] args)
{
String deals = null;
try
{
// Load the JDBC
Class.forName("com.mysql.jdbc.Driver");
// specify the data source's URL
String url = "jdbc:mysql://localhost/test";
// connect
Connection con = DriverManager.getConnection(url, "myuser","mypass");
// create and execute a SELECT
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM mytable;");
while (rs.next())
{
String fieldValue = rs.getString(1);
System.out.println("fieldValue: " + fieldValue);
}
// close statement and connection
stmt.close();
con.close();
}
catch (java.lang.Exception ex)
{
ex.printStackTrace();
}
}
}
The exception occurs in the call to "DriverManager.getConnection".
Any help is appreciated....
--------The Exception-------
java.sql.SQLException: Invalid authorization specification, message from server : "Access denied for user: 'myuser@VirtualServerName' (Using password: YES)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1752)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:833)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1734)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java :361)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DBTester.main(DBTester.java:23)
---------The Code------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBTester
{
public static void main(String[] args)
{
String deals = null;
try
{
// Load the JDBC
Class.forName("com.mysql.jdbc.Driver");
// specify the data source's URL
String url = "jdbc:mysql://localhost/test";
// connect
Connection con = DriverManager.getConnection(url, "myuser","mypass");
// create and execute a SELECT
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM mytable;");
while (rs.next())
{
String fieldValue = rs.getString(1);
System.out.println("fieldValue: " + fieldValue);
}
// close statement and connection
stmt.close();
con.close();
}
catch (java.lang.Exception ex)
{
ex.printStackTrace();
}
}
}