DB2 10.5 的 Hibernate 错误连接被拒绝:连接。错误代码=-4499,SQLSTATE=08001

Hibernate error for DB2 10.5 Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001

我是 Hibernate 新手。我正在尝试 运行 我的第一个 Hibernate 示例。

我已经在我的本地系统中安装了 db2 10.5 服务器。

我的 Hibernate 配置文件:

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>

    <property name="connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
    <property name="connection.url">jdbc:db2://localhost:5000/sample</property>
    <property name="connection.username">db2admin</property>
    <property name="connection.password">db2admin</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.DB2Dialect</property>

    <property name="show_sql">true</property>

    <mapping class ="com.googlesvn.practice.examples.hibernate.ramaschi.sample.miscDto.UserDetailsDto"></mapping>

  </session-factory>
</hibernate-configuration>

我的示例数据库已启动并且能够运行 查询。当我尝试 运行 我的示例休眠程序时,它抛出以下异常。

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.convert(BasicConnectionCreator.java:118)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
    at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
    at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
    at com.googlesvn.practice.examples.hibernate.runner.HibernateRunner.main(HibernateRunner.java:27)
Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2043][11550][4.19.26] 
Exception java.net.ConnectException: Error opening socket to server localhost/127.0.0.1 on port 5,000 with message: Connection refused: connect. ERRORCODE=-4499, SQLSTATE=08001
        at com.ibm.db2.jcc.am.kd.a(Unknown Source)
        at com.ibm.db2.jcc.am.kd.a(Unknown Source)
        at com.ibm.db2.jcc.t4.ac.a(Unknown Source)
        at com.ibm.db2.jcc.t4.ac.<init>(Unknown Source)
        at com.ibm.db2.jcc.t4.a.b(Unknown Source)
        at com.ibm.db2.jcc.t4.b.newAgent_(Unknown Source)
        at com.ibm.db2.jcc.am.Connection.initConnection(Unknown Source)
        at com.ibm.db2.jcc.am.Connection.<init>(Unknown Source)
        at com.ibm.db2.jcc.t4.b.<init>(Unknown Source)
        at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
        at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(Unknown Source)
        at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
        at com.ibm.db2.jcc.DB2Driver.connect(Unknown Source)
        at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
        ... 13 more
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:383)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:245)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:232)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
        at java.net.Socket.connect(Socket.java:539)
        at com.ibm.db2.jcc.t4.w.run(Unknown Source)
        at java.security.AccessController.doPrivileged(AccessController.java:251)
        ... 25 more

我的休眠属性是正确的。我可以从我的 websphere 管理控制台测试连接。

当我凝视连接被拒绝时:连接。 ERRORCODE=-4499,SQLSTATE=08001 错误,它说需要设置 tcpip 属性

db2set DB2COMM=tcpip

db2stop

db2 启动

我不知道应该在哪里运行这些推荐,我试过db2推荐window,它不起作用。

我正在使用 db2jcc4.jar 用于连接池表单 websphere 管理控制台

请帮我解决这个问题。 谢谢

DB2 默认使用端口 50000,但您在 JDBC URL 中指定了 5000。除非您在安装后专门修改了 DB2 配置,否则我会尝试在您的端口号中添加一个零:

<property name="connection.url">jdbc:db2://localhost:50000/sample</property>