E
EyesOnly1
Hi Leute,
hab nen prob...
will mit java auf ne mysql datenbank zugreifen ...geht aber leider net...
Verwnde den mysql-connector-java.
vllt kann mir jemand helfen hier der Quelltext u. die fehler Meldung
-----------------------------------------------------------------------------------------------------------------
import java.io.PrintWriter;
import java.sql.*;
public class db {
public static void main(String[] args) {
// Diese Eintraege werden zum
// Verbindungsaufbau benoetigt.
final String hostname = "localhost";
final String port = "3306";
final String dbname = "es";
final String user = "root";
final String password = "db";
String aus = null;
Connection conn = null;
try {
System.out.println("* Treiber laden");
Class.forName("com.mysql.jdbc.Driver");
// org.gjt.mm.mysql.Driver
System.out.println("* Treiber geladen");
DriverManager.setLogWriter( new PrintWriter(System.out) );
}
catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("* Verbindung aufbauen...echt?");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/es","root","db");
System.out.println("* Verbindung aufgebaut");
Statement stmt = conn.createStatement();
System.out.println("* Datenbank-Verbindung beenden");
conn.close();
}
catch (SQLException sqle) {
System.out.println("SQLException: " + sqle.getMessage());
System.out.println("SQLState: " + sqle.getSQLState());
System.out.println("VendorError: " + sqle.getErrorCode());
sqle.printStackTrace();
}
} // ende: public static void main()
} // ende: public class db
------------------------------------------
Fehlermeldung
* Treiber laden
* Treiber geladen
* Verbindung aufbauen...echt?
DriverManager.getConnection("jdbc:mysql://localhost:3306/es")
trying driver[className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@18d107f]
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.main(db.java:39)
getConnection failed: java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
SQLException: Communication failure during handshake. Is there a server running on localhost:3306?java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.main(db.java:39)
SQLState: null
VendorError: 0
--------------------------------------------------------
MFG
hab nen prob...
will mit java auf ne mysql datenbank zugreifen ...geht aber leider net...
Verwnde den mysql-connector-java.
vllt kann mir jemand helfen hier der Quelltext u. die fehler Meldung
-----------------------------------------------------------------------------------------------------------------
import java.io.PrintWriter;
import java.sql.*;
public class db {
public static void main(String[] args) {
// Diese Eintraege werden zum
// Verbindungsaufbau benoetigt.
final String hostname = "localhost";
final String port = "3306";
final String dbname = "es";
final String user = "root";
final String password = "db";
String aus = null;
Connection conn = null;
try {
System.out.println("* Treiber laden");
Class.forName("com.mysql.jdbc.Driver");
// org.gjt.mm.mysql.Driver
System.out.println("* Treiber geladen");
DriverManager.setLogWriter( new PrintWriter(System.out) );
}
catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("* Verbindung aufbauen...echt?");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/es","root","db");
System.out.println("* Verbindung aufgebaut");
Statement stmt = conn.createStatement();
System.out.println("* Datenbank-Verbindung beenden");
conn.close();
}
catch (SQLException sqle) {
System.out.println("SQLException: " + sqle.getMessage());
System.out.println("SQLState: " + sqle.getSQLState());
System.out.println("VendorError: " + sqle.getErrorCode());
sqle.printStackTrace();
}
} // ende: public static void main()
} // ende: public class db
------------------------------------------
Fehlermeldung
* Treiber laden
* Treiber geladen
* Verbindung aufbauen...echt?
DriverManager.getConnection("jdbc:mysql://localhost:3306/es")
trying driver[className=com.mysql.jdbc.Driver,com.mysql.jdbc.Driver@18d107f]
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.main(db.java:39)
getConnection failed: java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
SQLException: Communication failure during handshake. Is there a server running on localhost:3306?java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.main(db.java:39)
SQLState: null
VendorError: 0
--------------------------------------------------------
MFG