Zugriff auf mysql mit jdbc

hi,
ich versuche auf meinen server mit jdbc zuzugreifen und bekomme andauernd diese fehler
Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
zusätzliche systemouts.
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1564)
at com.mysql.jdbc.Connection.(Connection.java:485)
at com.mysql.jdbc.Driver.connect(Driver.java:341)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at net.maxcity.util.register.HelloMySQL.main(HelloMySQL.java:34)
SQLExecption: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect
SQLState: 08S01
VendorError: 0

Der source code sieht wiefolgt aus.
import java.sql.*;
public class HelloMySQL{
static String ConnectURL = „jdbc:mysql://111.111.111.111/dbname“;
public static void main(String Args[]) {
try {
Class.forName(„com.mysql.jdbc.Driver“).newInstance();
} catch (Exception e) {
System.err.println(„Unable to load driver.“);
System.err.println(e);
e.printStackTrace();
System.exit(-1);
}
System.out.println(„Driver loaded okay.“);
try {
Connection conn =
DriverManager.getConnection(ConnectURL,„user“,„pw“);
} catch (SQLException e) {
System.err.println(„Driver can’t get a connection.“);
e.printStackTrace();
System.err.println("SQLExecption: " + e.getMessage());
System.err.println("SQLState: " + e.getSQLState());
System.err.println("VendorError: " + e.getErrorCode());
System.exit(-1);
}
System.out.println(„We have a connection!“);
}
}

Hilfe es geht nicht. Die Daten sind okay, hab mich mal mit php konnekiert. mein lokaler suse-server funzt auch nur dieser server will nicht. Hat jemand eine Idee. das wäre ziemlich cool,
thx,
gruss ming

Hi.

Probiers mal mit diesem Connection-String:

String connectionString = „jdbc:mysql://host/db?user=user&password=passwd“;

Danach folgende Zeilen, um die Verbindung aufzubauen:

String driverName = „org.gjt.mm.mysql.Driver“;
try {
myDriver = (Driver)Class.forName(DriverName).newInstance();
myConnection = DriverManager.getConnection(connectionString);
} catch (Exception e) {
// Gib die Exception je nach System aus
}

Das funktioniert bei mir definitiv (JConnector). Wenn du dann immer noch die gleiche Fehlermeldung von wegen Connection Refused bekommst, solltest du mal deine Berechtigungen auf der MySQL-Engine checken.

mfG,

J.P.Jarolim

Hi,

es klappt, danke.

gruss ming