Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.com.mysql.jdbc.exception.jbbc4.communicationexception..通信链路故障_Mysql_Database_Jdbc - Fatal编程技术网

.com.mysql.jdbc.exception.jbbc4.communicationexception..通信链路故障

.com.mysql.jdbc.exception.jbbc4.communicationexception..通信链路故障,mysql,database,jdbc,Mysql,Database,Jdbc,当我尝试使用连接数据库的java应用程序时,我得到了上面的消息 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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. 这里我

当我尝试使用连接数据库的java应用程序时,我得到了上面的消息

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
这里我将在我的java应用程序中提到一些java代码;我用来连接数据库的

jDBC驱动程序名称和数据库URL

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
static final String DB_URL = "jdbc:mysql://localhost/SORTS";
用户和密码

static final String USER = "root";
static final String PASS = null;
注册JDBC驱动程序

  Class.forName("com.mysql.jdbc.Driver");
//正在连接到选定的数据库

conn = DriverManager.getConnection(DB_URL, USER, PASS);
我认为这些MySql服务器信息也可能有用

current database:sorts
current user:root@localhost
Connection:localhost via TCP/IP
TCP port:3307

在URL中,您应该添加使用的端口号3307,它不是标准端口号…:

 static final String DB_URL = "jdbc:mysql://localhost:3307/SORTS";

希望有帮助。

您确定您的数据库正在运行吗?检查并确保数据库服务器已启动并正在运行。此外,考虑到塔库西街aswer