2

当应用程序尝试与 DB 建立连接时,我遇到了通信链接故障。

[#|2010-04-08T20:09:57.825+0300|SEVERE|glassfish3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|Cannot connect to database server = 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.|#]

正是在这个字符串:

Statement s = conn.createStatement();

其中conn定义如下:

private static java.sql.Connection conn;

对于这个应用程序,我设置了一个带有默认参数的连接池,目前它(应用程序)同时使用 JPA 和直接 JDBC 查询。连接池的重新创建什么也没做,连接池 ping 给出了下一条消息:

Ping Connection Pool for pool is Failed. Ping failed Exce
ption - Connection could not be allocated because: Communications lin
k failure%%%EOL%%%%%%EOL%%%The last packet sent successfully to the s
erver was 0 milliseconds ago. The driver has not received any packets
from the server. Please check the server.log for more details.%%%EOL
%%%Ping failed Exception - Connection could not be allocated because:
Communications link failure

并刷新连接池给出:

com.sun.enterprise.admin.cli.CommandException: remote failure: Failed to flush connection pool ...

但是我可以从终端连接到数据库。此外,我有相同的应用程序在我的本地机器上运行,具有相同的连接池设置。

任何人都知道发生了什么或如何解决问题?

4

3 回答 3

3

这样的问题可能是如果您在同一主机上拥有 mysql 服务器和 glassfish 服务器,并且在 mysql 配置中,您有选项绑定到某个公共地址(例如 eth0 接口的 192.168.0.1),通常使用用户成功使用简单的 jdbc/jpa @localhost,但在 glassfish JTA 的情况下它们不会,而是绑定到一些本地地址,您会遇到链接失败。通常,如果提供公共地址,您不能绑定到此类 mysql 主机的任何本地 (localhost/127.0.0.1) 地址。

例子:

我的.cnf

绑定地址 = 127.0.0.1

绑定地址 = 192.168.0.1

127.0.0.1 - 分配给 lo 接口

192.168.0.1 - 分配给 eth0 接口

这是 glassfish-mysql 的错误。

目前为了使用 JTA,你不应该将 mysql 绑定到这样的地址。(从 my.cnf 中删除“bind-address=192.168.0.1”)。或者使用 user@192.168.0.1 不太安全。

于 2010-04-10T11:35:37.810 回答
0

此外,我有相同的应用程序在我的本地机器上运行,具有相同的连接池设置。

你连接到同一个数据库吗?如果是,请检查您是否使用相同的 JDBC 驱动程序。

于 2010-04-10T04:36:31.700 回答
0

就我而言,我设置: URL:jdbc:mysql://10.81.35.66:3306/testDB 和 url:jdbc:mysql://10.81.31.76:3306/vectordb

在 glass fish 管理控制台的附加属性部分中创建连接池时设置值。

于 2018-06-19T15:14:21.143 回答