JDBC connection to remote MySql fails

时光怂恿深爱的人放手 提交于 2019-12-11 23:46:36

问题


In glassfish(3.1.2) I have created a JDBC Connection Pool (and JDBC Resource) to a remote MySql database. When a do a ping test in glassfish it is successful.

My Java EE 6 app is using that persistence unit(persistence.xml):

<persistence-unit name="remotePU" transaction-type="JTA">
    <jta-data-source>jdbc/remotePU</jta-data-source>
    <properties> 
    </properties>
</persistence-unit>

In a dao I inject a persistence context:

@PersistenceContext(unitName = "remotePU")
private EntityManager em;

Then I just use this entity manager to query.

I have also tested this same setup with a local database and that worked fine, so I know the error is not in the code.

The exception stack I get when I query is:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
....
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
....
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

Is the remote connection just to slow? This is a ping to the server of the remote database:

Pinging xxxxx.net [xx.xx.xx.xx] with 32 bytes of data:
Reply from xx.xx.xx.xx: bytes=32 time=29ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54

Ping statistics for xx.xx.xx.xx:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 28ms, Maximum = 29ms, Average = 28ms

Can I adjust some JDBC Connection pool settings in Glassfish to have a better connection?

来源:https://stackoverflow.com/questions/13281683/jdbc-connection-to-remote-mysql-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!