与远程MySql服务器的{Hibernate连接

时间:2016-07-01 12:25:22

标签: java mysql hibernate

我一直在尝试从局域网访问MySql服务器,它与#34; localhost" ,但无法从Hibernate远程访问服务器。

MySql querybrowser是一个能够访问远程服务器,Ping工作正常,浏览过SO和互联网的错误,我每次都会得到:

通讯链接错误 和 无法读取服务器的响应。预计读取4个字节,在连接意外丢失之前读取0个字节。

这是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>

连接超时,防火墙端口,权限授予,所有事情都已经过尝试但似乎错误。

这些是我们使用的工具和技术: 日食, 雄猫, 休眠4 Mysql 5 Struts 2

注意:Telnet 192.168.0.15 3306有效,能够从mysql查询浏览器连接,

请在这里指导我。

这里是完整的堆栈跟踪:

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

谢谢。

0 个答案:

没有答案