DB2 10.5 Connection的Hibernate错误拒绝:连接。 ERRORCODE = -4499,SQLSTATE = 08001

时间:2015-02-21 22:27:41

标签: java hibernate db2

我是新的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>

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

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)
    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

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

当我护目镜连接被拒绝时:连接。 ERRORCODE = -4499,SQLSTATE = 08001错误,表示需要设置tcpip属性

db2set DB2COMM = tcpip

DB2STOP

db2start

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

我正在使用db2jcc4.jar,我用它来连接池形式的websphere管理控制台

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

1 个答案:

答案 0 :(得分:2)

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

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