Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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
Java (Enterprise GlassFish v3构建11)通信链路问题(MySQL数据库)_Java_Mysql_Glassfish_Connection Pooling_Java Ee 6 - Fatal编程技术网

Java (Enterprise GlassFish v3构建11)通信链路问题(MySQL数据库)

Java (Enterprise GlassFish v3构建11)通信链路问题(MySQL数据库),java,mysql,glassfish,connection-pooling,java-ee-6,Java,Mysql,Glassfish,Connection Pooling,Java Ee 6,当应用程序尝试与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.Commu

当应用程序尝试与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 ...
但是,我可以从终端连接到数据库。此外,我有相同的应用程序在我的本地机器上使用相同的连接池设置

有人知道发生了什么或如何解决问题吗

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


您正在连接到同一个数据库吗?如果是,可以检查您使用的是同一个JDBC驱动程序。

如果您在同一台主机上有mysql服务器和glassfish服务器,并且在mysql配置中,您有选项绑定到某个公共地址(例如eth0接口的192.168.0.1),该地址通常使用user@localhost,但在glassfish JTA的情况下,它们不会绑定到某些本地地址,因为链接失败。通常,如果提供公共地址,则不能绑定到此类mysql主机的任何本地(localhost/127.0.0.1)地址

例如:

my.cnf

绑定地址=127.0.0.1

绑定地址=192.168.0.1

127.0.0.1-分配给lo接口

192.168.0.1-分配给eth0接口

这是玻璃鱼

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

在我的情况下,我设置: URL:jdbc:mysql://10.81.35.66:3306/testDB 及 url:jdbc:mysql://10.81.31.76:3306/vectordb

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

标题具有版本id。。。因此,将glassfishv3改为glassfish