views:

336

answers:

2

I get a communication link failure while application tries to establish a connection with 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.|#]

Precisely at this string:

Statement s = conn.createStatement();

where conn is defined as follows:

private static java.sql.Connection conn;

For this app I have set a connection pool with default parameters and currently it (app) uses both JPA and direct JDBC queries. Recreation of connection pool gave nothing, connection pool ping gave next 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 flushing 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 a terminal. Besides I have the same app working on my local machine with identical connection pool settings.

Any one has an idea on whats going on or how to solve the trouble?

A: 

Besides I have the same app working on my local machine with identical connection pool settings.

Are you connecting to the same database? If yes, maybe check that you're using the same JDBC driver.

Pascal Thivent
+1  A: 

Such problem could be if you have mysql server & glassfish server on the same host, and in mysql configuration you have option bind to some public address (for example 192.168.0.1 of eth0 interface) that normally successfully working with simple jdbc/jpa using user@localhost, but they don`t in a case of glassfish JTA, instead to bind to some of local address you getting link failure. As rule you could not bind to any local (localhost/127.0.0.1) addresses of such mysql host if public address presented.

Example:

my.cnf

bind-address = 127.0.0.1

bind-address = 192.168.0.1

127.0.0.1 - assign to lo interface

192.168.0.1 - assign to eth0 interface

It is glassfish-mysql bug.

Currently in order to use JTA, you should not bind mysql to such address. (remove "bind-address=192.168.0.1" from my.cnf). Or use [email protected] what is less secure.

kislo_metal