** Mysql5.6 was used for JDBC connection, but now it cannot be used. I have found the cause on the internet but cannot find a solution, the connection JAR package is mysql-connector-java-5.1.26-bin.jar, please know the great God to answer a little ** This is to use JDBC connection MYSQLimportjava. SQL. *; publicclassTestMysqlConnection {publicstaticvoidmain (String [] args) {Connectioncon... connect mysqleclipse to mysqljava
I used mysql 5.6 to connect to mysql using JDBC, but now it cannot be used. I am not clear about the reason and have found it online, but I cannot find a solution, connecting JAR package is mysql-connector-java-5.1.26-bin.jar, please know the great God to answer the younger brother
This is to use JDBC to connect to MYSQL
Import java. SQL .*;
Public class TestMysqlConnection {
Public static void main (String [] args ){
Connection conn = null;
Try {
Class. forName ("com. mysql. jdbc. Driver ");
Conn = DriverManager. getConnection ("jdbc: mysql: // localhost/bbs", "root", "82215378 ");
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (SQLException e ){
E. printStackTrace ();
} Finally {
Try {
If (conn! = Null ){
Conn. close ();
Conn = null;
}
} Catch (SQLException e ){
E. printStackTrace ();
}
}
}
The error is as follows:
Com. mysql. jdbc. exceptions. jdbc4.MySQLNonTransientConnectionException: Communication link failure, message from server: "Can't get hostname for your address"
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. NativeConstructorAccessorImpl. newInstance (Unknown Source)
At sun. reflect. DelegatingConstructorAccessorImpl. newInstance (Unknown Source)
At java. lang. reflect. Constructor. newInstance (Unknown Source)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. Util. getInstance (Util. java: 386)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 1015)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 989)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 975)
At com. mysql. jdbc. MysqlIO. doHandshake (MysqlIO. java: 1112)
At com. mysql. jdbc. ConnectionImpl. coreConnect (ConnectionImpl. java: 2486)
At com. mysql. jdbc. ConnectionImpl. connectOneTryOnly (ConnectionImpl. java: 2519)
At com. mysql. jdbc. ConnectionImpl. createNewIO (ConnectionImpl. java: 2304)
At com. mysql. jdbc. ConnectionImpl. (ConnectionImpl. java: 834)
At com. mysql. jdbc. JDBC4Connection. (JDBC4Connection. java: 47)
At sun. reflect. NativeConstructorAccessorImpl. newInstance0 (Native Method)
At sun. reflect. NativeConstructorAccessorImpl. newInstance (Unknown Source)
At sun. reflect. DelegatingConstructorAccessorImpl. newInstance (Unknown Source)
At java. lang. reflect. Constructor. newInstance (Unknown Source)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)
At com. mysql. jdbc. ConnectionImpl. getInstance (ConnectionImpl. java: 416)
At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 346)
At java. SQL. DriverManager. getConnection (Unknown Source)
At java. SQL. DriverManager. getConnection (Unknown Source)
At TestMysqlConnection. main (TestMysqlConnection. java: 8)