java program works for MySQL on Windows, but not Linux
Posted by: william fu
Date: February 04, 2005 08:50AM

I have a simple Java program that opens a connection to MySQL server and close the connection. It works fine on the Windows MySQL. However, when I migrate my program to the Linux machine. I always get the following message:

SQLException:
SQLState: 28000
Message: Access denied for user 'root@localhost.localdomain' (Using password: YES)
Vendor: 1045

Does anyone have the similar experience when run your program on a Linux MySQL? Attached is the simple program. Please drop me few lines.

William

-------

import java.sql.*;
import java.io.*;
import java.util.*;

public class DBManager {

public static Connection getConnection(String url, String userName, String password)
throws SQLException
{
String jdbc_drivers = "com.mysql.jdbc.Driver";
System.setProperty("jdbc.drivers", jdbc_drivers);
return
DriverManager.getConnection(url, userName, password);
}

public static void closeConnection(Connection con)
throws SQLException
{
if(con != null)
con.close();
}

public static void main(String[] args) {

Connection conn = null;
try {
String userName = "root";
String password = "mypassword";
String dbName = "mysql";
String url = "jdbc:mysql://localhost/" + dbName;
//Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = getConnection(url, userName, password);
System.out.println("Database connection established");
}
catch (SQLException ex)
{
System.out.println ("SQLException:");
while (ex != null)
{ System.out.println ("SQLState: "
+ ex.getSQLState());
System.out.println ("Message: "
+ ex.getMessage());
System.out.println ("Vendor: "
+ ex.getErrorCode());
ex = ex.getNextException();
System.out.println ("");
}
}
}
}

Options: ReplyQuote


Subject
Written By
Posted
java program works for MySQL on Windows, but not Linux
February 04, 2005 08:50AM


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.