Java 8升级后无法获得数据库连接 [英] Unable to get db connection after Java 8 upgrade

查看:132
本文介绍了Java 8升级后无法获得数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将应用程序从Java 1.7升级到了1.8.其余库版本保持不变.升级后出现以下错误:

I have recently upgraded an application from java 1.7 to 1.8. Rest of the libraries versions remains unchanged. I am getting the following error after the upgrade:

DEBUG 2015-11-12 09:55:12 BasicResourcePool         An exception occurred while acquiring a poolable resource. Will retry.
java.lang.NullPointerException
    at oracle.net.jndi.JndiAttrs.getAttrs(JndiAttrs.java:207)
    at oracle.net.resolver.AddrResolution.<init>(AddrResolution.java:198)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:219)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

休眠配置:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@ldaps://XXXX,cn=OOOO,dc=WWW</property>
        <property name="hibernate.connection.username">YYYY</property>
        <property name="hibernate.statement_cache.size">0</property>
        <property name="hibernate.connection.password">ZZZZZ</property>
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">1800</property>
        <property name="hibernate.c3p0.max_statements">0</property>
        <property name="hibernate.default_schema">YYYY</property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="hibernate.show_sql">true</property>
    </session-factory>
</hibernate-configuration>

使用的相关库:

  • ojdbc6 11.2.0.3.0
  • 休眠3.1

问题: 依赖项包含2个休眠版本3.1和3.0以及ojdbc6和ojdbc7. (用于获取依赖树的mvn dependency:tree -Dverbose

Problem: The dependencies contained 2 hibernate version 3.1 and 3.0 and ojdbc6 and ojdbc7. (used mvn dependency:tree -Dverbose to got dependency tree)

解决方案: 从依赖项中排除了其他版本的hibernate和ojdbc.

Solution: Excluded the other versions of hibernate and ojdbc from the dependencies.

            <dependency>
                <groupId>****</groupId>
                <artifactId>****</artifactId>
                <version>****</version>
                <exclusions>
                    <exclusion>
                        <groupId>hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc6</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

推荐答案

正如我从

As i can see from the Oracle FAQ, the jdbc driver you are using is not compatible with the Database Version and JDK8.

支持哪些受支持的Oracle数据库版本与JDBC兼容版本以及JDK版本?

What are the various supported Oracle database version vs JDBC compliant versions vs JDK version supported?

我认为这一定是您的问题.也许如果您使用ojdbc7.jar可能会有所帮助(不确定这个原因,我尚未对其进行测试-大多数可能会失败)

I think this must be your problem. Maybe if you used ojdbc7.jar might help (not sure about this cause I haven't tested it yet - MOST PROBABLY THIS WOULD FAIL)

这篇关于Java 8升级后无法获得数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆