我正在尝试使用hibernate连接到远程数据库(托管在Netfirms www.netfirms.ca上,如果有人好奇的话)。我的映射文件如下:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://mysql.netfirms.ca:3306/d60549476</property>
<property name="hibernate.connection.username">u70612250</property>
<property name="hibernate.connection.password">******</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- List of XML mapping files -->
<mapping resource="customer.hbm.xml"/>
<mapping resource="customerSummary.hbm.xml"/>
<mapping resource="charity.hbm.xml"/>
<mapping resource="charitySummary.hbm.xml"/>
</session-factory>
</hibernate-configuration>
当我启动我的应用程序时,我得到以下打印输出:
16 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
....
94 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
....
485 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
532 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
532 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
547 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
547 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://mysql.netfirms.ca:3306/d60549476
547 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=u70612250, password=****}
168719 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection metadata
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.NoRouteToHostException
MESSAGE: No route to host: connect
STACKTRACE:
java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
我确保我的数据库配置为允许远程访问。我想知道是什么原因引起的。显然,我无法与主机建立连接,但我不确定原因。假设主机名,用户和密码是正确的,我错过了什么吗?
附录:我尝试使用与Squirrel相同的驱动程序连接,并得到了同样的错误。
答案 0 :(得分:1)
事实证明连接有几个问题:
感谢大家的帮助。
答案 1 :(得分:0)
我想第一步是检查(因为你没有说你已经尝试过),如果你可以使用一些SQL工具连接到数据库。比如SQuirrel。
答案 2 :(得分:0)
Exception说,没有到主机的路由。这意味着你很可能甚至无法ping你的数据库服务器。
阅读http://support.netfirms.com/article.php?id=694你应该把另一个主机放在你的jdbc网址
中JDBC:MySQL的://mysql.netfirms的玉米强>:3306 / d60549476