(Enterprise GlassFish v3 build 11) Communication issue (MySQL DB)

I am getting a communication error while the application is trying to establish a connection to the 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.|#]

      

It is on this line:

Statement s = conn.createStatement();

      

where conn is defined as follows:

private static java.sql.Connection conn;

      

For this application I have set up a connection pool with default options and it currently (the application) uses both JPA and JDBC direct requests. Disconnecting the connection pool gave nothing, the connection pool gave the following message:

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

      

and resetting the connection pool gave:

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

      

However, I can connect to the database from the terminal. Also, I have the same application running on my local machine with the same connection pooling settings.

Anyone have an idea on what is going on or how to fix the problem?

+2


source to share


2 answers


Such a problem can arise if you have a mysql server and glassfish on the same host, and in your mysql config you have the option to bind to some public address (for example 192.168.0.1 from the eth0 interface), which usually works successfully with a simple jdbc / jpa using user @ localhost, but they don't in the case of JTA Glassfish, instead you get a refusal to bind to a local address. Generally, you cannot bind to the local (localhost / 127.0.0.1) addresses of such a mysql host if the public address is present.

Example:

my.cnf

bind-address = 127.0.0.1

bind-address = 192.168.0.1



127.0.0.1 - assign lo interface

192.168.0.1 - assign interface eth0

This is a glassfish-mysql bug.

Currently, to use JTA, you should not bind mysql to such an address. (remove "bind-address = 192.168.0.1" from my.cnf). Or use user@192.168.0.1 , which is less secure.

+3


source


Also, I have the same application running on my local machine with the same connection pooling settings.



Are you connecting to the same database? If so, maybe check that you are using the same JDBC driver.

0


source







All Articles