db2驱动与jdk版本关系

db2驱动与jdk版本关系

错误描述

项目需要使用db2数据库,发现jdk1.8与db2驱动包有冲突,提示错误如下:

[2019-10-16 17:31:52,305][INFO][LocalSessionFactoryBean.buildSessionFactory() 743] Building new Hibernate SessionFactory
[2019-10-16 17:31:52,358][INFO][ConnectionProviderFactory.newConnectionProvider() 72] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
[2019-10-16 17:31:52,397][INFO][AbstractPoolBackedDataSource.getPoolManager() 462] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge25va51mspar216mqzcd|518caac3, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.ibm.db2.jcc.DB2Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge25va51mspar216mqzcd|518caac3, idleConnectionTestPeriod -> 120, initialPoolSize -> 3, jdbcUrl -> jdbc:db2://192.168.1.108:50000/test:progressiveStreaming=2;, lastAcquisitionFailureDefaultUser -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 25200, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 300, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 2, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
[2019-10-16 17:31:52,642][INFO][SQLWarnings.logAndClearWarnings() 43] Origination unknown: [10228][11541][3.50.152] 在装入驱动程序时发生了安全性异常。 ERRORCODE=4223, SQLSTATE=null
com.ibm.db2.jcc.b.SqlWarning: Origination unknown: [10228][11541][3.50.152] 在装入驱动程序时发生了安全性异常。 ERRORCODE=4223, SQLSTATE=null
	at com.ibm.db2.jcc.b.wc.b(wc.java:163)
	at com.ibm.db2.jcc.b.wc.b(wc.java:217)
	at com.ibm.db2.jcc.b.db.c(db.java:536)
	at com.ibm.db2.jcc.b.eb.a(eb.java:436)
	at com.ibm.db2.jcc.b.eb.(eb.java:417)
	at com.ibm.db2.jcc.t4.b.(b.java:296)
	at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:193)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
	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)
Caused by: java.security.PrivilegedActionException: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter
	at java.security.AccessController.doPrivileged(Native Method)
	at com.ibm.db2.jcc.b.db.m(db.java:522)
	at com.ibm.db2.jcc.b.db.(db.java:339)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.ibm.db2.jcc.DB2Driver.class$(DB2Driver.java:57)
	at com.ibm.db2.jcc.DB2Driver.(DB2Driver.java:60)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:101)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:133)
	... 7 more

如果DB2服务器为本机

查看db2版本信息:

db2licm -l
产品名:                          "DB2 Express-C"
许可证类型:                     "无担保"
到期日期:                        "永久"
产品标识:                       "db2expc"
版本信息:                        "10.5"
最大 CPU 数目:                  "2"
最大内存量 (GB):               "16"
强制策略:                        "软停止"

打印驱动程序名称和版本

java com.ibm.db2.jcc.DB2Jcc -version
IBM Data Server Driver for JDBC and SQLJ 3.69.24

打印驱动程序配置信息:说明数据自带的驱动包,仅支持jdk1.6

java com.ibm.db2.jcc.DB2Jcc -configuration
[jcc] BEGIN TRACE_DRIVER_CONFIGURATION
[jcc] Driver: IBM Data Server Driver for JDBC and SQLJ 3.69.24
[jcc] Compatible JRE versions: { 1.4, 1.5, 1.6 }

如果本机未安装db2

打开项目jar包目录,输入如下命令查看db2jcc包程序配置信息:

java -cp ./db2jcc.jar com.ibm.db2.jcc.DB2Jcc -configuration
[jcc] BEGIN TRACE_DRIVER_CONFIGURATION
[jcc] Driver: IBM Data Server Driver for JDBC and SQLJ 4.25.13
[jcc] Compatible JRE versions: { 1.6, 1.7, 1.8 }

db2官方文档

db2官方文档中描述db2 v10.5 FP7版本驱动和jdk1.8兼容,所以下载高版本的db2jcc驱动即可解决问题:

JDK/JRE 1.8 support first included with JDBC drivers bundled with v10.5 FP7.

maven配置



	com.ibm.db2.jcc
	db2jcc
	db2jcc4

参考:

https://www.ibm.com/support/pages/db2-jdbc-driver-versions-and-downloads

你可能感兴趣的:(db2)