代码之家  ›  专栏  ›  技术社区  ›  Denys S.

(Enterprise GlassFish v3 Build 11)通信链接问题(MySQL DB)

  •  2
  • Denys S.  · 技术社区  · 14 年前

    当应用程序试图建立与数据库的连接时,我收到一个通信链接故障。

    [#|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();
    

    哪里 康恩 定义如下:

    private static java.sql.Connection conn;
    

    对于这个应用程序,我用默认参数设置了一个连接池,目前它(app)同时使用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 ...
    

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

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

    3 回复  |  直到 6 年前
        1
  •  3
  •   kislo_metal    14 年前

    如果mysql服务器和glassfish服务器位于同一主机上,并且在mysql配置中,您可以选择绑定到一些公共地址(例如eth0接口的192.168.0.1),这些地址通常使用user@localhost成功地与简单的jdbc/jpa一起工作,但它们不在一个glassfish jta的例子,相反,绑定到一些本地地址会导致链接失败。通常,如果出现公共地址,则不能绑定到此类mysql主机的任何本地(local host/127.0.0.1)地址。

    例子:

    肌动蛋白

    绑定地址=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,这是不太安全的。

        2
  •  0
  •   Pascal Thivent    14 年前

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

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

        3
  •  0
  •   Devendra Singraul    6 年前

    在我的情况下,我设置: 网址:jdbc:mysql://10.81.35.66:3306/testdb 和 网址:jdbc:mysql://10.81.31.76:3306/vectordb

    在其他属性部分中创建连接池时设置值时 在玻璃鱼管理控制台上。