Java与MYSQL服务器的连接
我知道这个问题已经讨论了很多次,但我无法在我的Java应用程序和MySQL服务器之间建立连接 我正在使用代码表单教程:Java与MYSQL服务器的连接,java,mysql,connection,Java,Mysql,Connection,我知道这个问题已经讨论了很多次,但我无法在我的Java应用程序和MySQL服务器之间建立连接 我正在使用代码表单教程: import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class JDBCTest{ private Connection conn = null; public void connect(){ try { Cl
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCTest{
private Connection conn = null;
public void connect(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("test");
conn = DriverManager.getConnection("jdbc:mysql://mysql.***.***.**:3306/******","*******","top_secret_password");
System.out.println("test2");
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " ex.getMessage());
System.out.println("SQLState: " ex.getSQLState());
System.out.println("VendorError: " ex.getErrorCode());
}catch(Exception e){e.printStackTrace();}
}
}
发生的错误是:
test
SQLException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
SQLState: 08S01
VendorError: 0
您知道如何修复它吗?尝试提供数据库的
IP地址而不是名称。
说
并确保您的防火墙不会阻止3306
端口看起来与
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/*******","*******","top_secret_password");