JDBC problems...
Posted by: coglethorpe
Date: August 01, 2005 01:39PM

I'm on a system where I used Plesk/phpMyAdmin to configure a MySQL database, table and user. I can connect to the database as the user and perform queries on the table from the command line. However, when I attempt to use JDBC to connect, I receive an exception.

I know the user and password are right from the command line. I've also run the sample code against a DB on another (windows) system just fine.

Any help is appreicated. The details are below...

The jar I am using is: mysql-connector-java-3.0.9-stable-bin.jar

I'm running MySQL like this: /usr/bin/safe_mysqld --defaults-file=/etc/my.cnf

where /etc/my.cnf looks like this:

[mysqld]
safe-show-database
innodb_data_file_path=ibdata1:10M:autoextend
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

My source code looks like this:

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
{

System.out.println("Load the JDBC");
Class.forName("com.mysql.jdbc.Driver");

// specify the data source's URL
String url = "jdbc:mysql:///test";

System.out.println("Connect"); // connect
Connection con = DriverManager.getConnection(url, "myuser","mypass");

System.out.println("Select"); //
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM mytable;");

System.out.println("while..."); //
while (rs.next())
{

String fieldValue = rs.getString(1);

System.out.println("fieldValue: " + fieldValue);

}
// close statement and connection
System.out.println("close..."); //
stmt.close();
con.close();
}
catch (java.lang.Exception ex)
{

ex.printStackTrace();
}

}
}

And the exception looks like this:

java.sql.SQLException: Invalid authorization specification, message from server: "Access denied for user: 'myuser@VirtualUbilik' (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)

Options: ReplyQuote


Subject
Written By
Posted
JDBC problems...
August 01, 2005 01:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.