Ich bin ein Neuling für JDBC. Ich bin gerade auf eine SQLException gestoßen, als ich versucht habe, mein Java-Programm mit der Mysql-Datenbank zu verbinden.JDBC-Verbindungsfehler: java.sql.SQLException: Kommunikationsverbindungsfehler: Schlechter Handshake
Bitte die Details Laufzeitfehler unten finden:
Exception in thread "main" java.sql.SQLException: Communication link failure: Bad handshake
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(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at databaseexample.DatabaseExample.connect(DatabaseExample.java:40)
at databaseexample.DatabaseExample.main(DatabaseExample.java:26)
/home/sreejith/.cache/netbeans/8.2/executor-snippets/run.xml:53: Java returned: 1
Program Details :
package databaseexample;
import java.sql.*
;
public class DatabaseExample {
static boolean flag = false;
static String DBURL = "jdbc:mysql://localhost:3306/testdb";
static String CHECK_SQL_QUERY = "SELECT 1";
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// TODO code application logic here
Class.forName("com.mysql.jdbc.Driver");
flag = connect();
if(flag == true)
{
System.out.println("Connnected !");
} else
{
System.out.println("not connected.");
}
}
public static boolean connect() throws SQLException {
Connection conn = DriverManager.getConnection(DBURL,"root","root");
return true;
}
}
ich Telnet-Port 3306 versucht haben und empfangen, wie unten ein Ergebnis:
[email protected]:~$ telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
[
5.7.19-0ubuntu0.16.04.1*4` `iw2)Ml,L*
Lmysql_native_password
!#08S01Got packets out of orderConnection closed by foreign host.
ich auf Ubuntu 16.04 auf dem Wege renne. Vielen Dank im Voraus :)
Prüfung möglich Duplikat: https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc- und-mysql –