Hallo,
Wenn ich den JDBC Treiber über
lade, bekomme ich folgende Fehlermeldung auf der Console:
-----------------------------------
Exception: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at Mysqltest.main(Mysqltest.java:7)
** END NESTED EXCEPTION **
-----------------------------------
Mein Programm:
Danke, Hannes
Wenn ich den JDBC Treiber über
Code:
java -cp .:/etc/java/mysql-connector-java-3.0.16-ga-bin.jar Mysqltest
lade, bekomme ich folgende Fehlermeldung auf der Console:
-----------------------------------
Exception: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection refused
STACKTRACE:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at Mysqltest.main(Mysqltest.java:7)
** END NESTED EXCEPTION **
-----------------------------------
Mein Programm:
Code:
import java.net.*;
import java.sql.*;
class Mysqltest
{
public static void main(String args[])
{
String conn;
String dbHost = "localhost";
int dbPort = 3306;
String dbName = "test";
String user = "user";
String passwd = "xxx";
try
{
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Treiber kann nicht geladen werden: "+cnfe.getMessage());
}
try
{
conn = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, user, passwd);
}
catch(SQLException sqle)
{
System.out.println("Verbindung ist fehlgeschlagen: " + sqle.getMessage());
}
if (conn != null)
{
try
{
conn.close();
}
catch(SQLException sqle)
{
System.out.print(sqle.getMessage());
}
}
}
}
Danke, Hannes