1

I have been trying to access MySql server from LAN , it was working fine with "localhost" , but unable to access the server remotely from Hibernate .

MySql querybrowser is a able to access remote server , Ping works fine , have browsed SO and internet for this error , which i get every time :

Communications link error and Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

Here is Hibernate.cfg.xml

<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="connection.url">
            jdbc:mysql://192.168.0.15:3306/emrp  
        </property>
        <property name="connection.username">username</property>
        <property name="connection.password">password</property>
        <property name="connection.pool_size">10</property>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">
            org.hibernate.cache.NoCacheProvider
        </property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
</hibernate-configuration>

connection timeout , firewall ports , privilege grants , all the things have been tried out but the error seems to come .

These are the tools and tech which we are using : Eclipse , Tomcat , Hibernate 4 Mysql 5 Struts 2

Note : Telnet 192.168.0.15 3306 works , able to connect from mysql query browser ,

please guide me here .

here is full stack trace :

org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:118)
...
...
...
    Caused by: 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:781)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
    ... 109 more
Caused by: 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.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:675)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1078)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2142)
    ... 119 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2497)
    at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:599)
    ... 121 more

Thank you .

Roman C
  • 49,761
  • 33
  • 66
  • 176
Rakesh Bk
  • 112
  • 15
  • Could you please provide full error stack trace.Additionally you might want to have a look over http://stackoverflow.com/questions/10048296/error-in-mysql-connection-when-accessing-a-remote-server – Ankit Tripathi Jul 01 '16 at 12:32
  • Hi , Thanks for that link , have posted full stack trace , have tried most solutions given there , will try whats remaining , Hope they work . – Rakesh Bk Jul 01 '16 at 12:55
  • Have you checked this [link](http://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql) to allow remote MySQL and set bind address? – techtabu Jul 01 '16 at 15:10
  • Yeah , my.ini doesn't have a bind-address parameter , and i have granted all permissions , important thing it , when one connects from 32 bit computer it works !!!! – Rakesh Bk Jul 05 '16 at 04:10

0 Answers0