db2 驱动程序错误但能够建立连接

db2 driver error but able to establish connection

我正在尝试将 C3P0 连接池用于 IBM DB2 版本 10.5.5 修复包 5 和 Java 8。

最初,我得到 this error,所以我将 jar 更改为 db2jcc4.jar,但我仍然在控制台中遇到以下错误,

1350 [C3P0PooledConnectionPoolManager[identityToken->2x0fal9iui9mpmdj6im3|c2e1f26]-HelperThread-#1] INFO  com.mchange.v2.c3p0.SQLWarnings  – Origination unknown: [10228][11541][4.11.77] Security exceptions occurred while loading driver. ERRORCODE=4223, SQLSTATE=null
com.ibm.db2.jcc.am.SqlWarning: Origination unknown: [10228][11541][4.11.77] Security exceptions occurred while loading driver. ERRORCODE=4223, SQLSTATE=null
    at com.ibm.db2.jcc.am.gd.b(gd.java:207)
    at com.ibm.db2.jcc.am.gd.b(gd.java:258)
    at com.ibm.db2.jcc.am.jb.a(jb.java:887)
    at com.ibm.db2.jcc.am.lb.a(lb.java:574)
    at com.ibm.db2.jcc.am.lb.<init>(lb.java:555)
    at com.ibm.db2.jcc.t4.b.<init>(b.java:305)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:460)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
    at com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.security.PrivilegedActionException: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.db2.jcc.am.jb.r(jb.java:873)
    at com.ibm.db2.jcc.am.jb.<clinit>(jb.java:484)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:117)
    ... 9 more
Caused by: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.ibm.db2.jcc.am.jg.run(jg.java:19)
    ... 13 more
1350 [C3P0PooledConnectionPoolManager[identityToken->2x0fal9iui9mpmdj6im3|c2e1f26]-HelperThread-#0] INFO  com.mchange.v2.c3p0.SQLWarnings  – Origination unknown: [10228][11541][4.11.77] Security exceptions occurred while loading driver. ERRORCODE=4223, SQLSTATE=null
com.ibm.db2.jcc.am.SqlWarning: Origination unknown: [10228][11541][4.11.77] Security exceptions occurred while loading driver. ERRORCODE=4223, SQLSTATE=null
    at com.ibm.db2.jcc.am.gd.b(gd.java:207)
    at com.ibm.db2.jcc.am.gd.b(gd.java:258)
    at com.ibm.db2.jcc.am.jb.a(jb.java:887)
    at com.ibm.db2.jcc.am.lb.a(lb.java:574)
    at com.ibm.db2.jcc.am.lb.<init>(lb.java:555)
    at com.ibm.db2.jcc.t4.b.<init>(b.java:305)
    at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:460)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
    at com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.security.PrivilegedActionException: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.db2.jcc.am.jb.r(jb.java:873)
    at com.ibm.db2.jcc.am.jb.<clinit>(jb.java:484)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:117)
    ... 9 more
Caused by: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.ibm.db2.jcc.am.jg.run(jg.java:19)
    ... 13 more

即使日志中存在此错误,我的独立 Java 应用程序也能够连接到数据库并获取结果,即 SELECT 查询已成功执行。

如何解决这个困惑?

您看到的堆栈跟踪来自 SqlWarning 对象,这可能意味着它们不是致命或严重的问题。明显的问题 java.lang.ClassNotFoundException: sun.io.ByteToCharConverter 看起来很奇怪。但是由于它是作为警告而不是作为异常抛出的,驱动程序可能已经从问题中恢复过来,这就是为什么您的应用程序似乎可以正常工作。

JDBC 允许连接存储 a chain of SQLWarnings,这可能来自任何事物,但大多数应用程序会忽略它。 (大多数 JDBC 程序员甚至不知道它们的存在。)

c3p0 对定期检查 Connection 警告、记录它们然后清除它们非常神经质,这样 Connections 的用户就不会看到来自先前客户端使用的警告。但是,警告的日志记录可能很烦人,因此如果您愿意,可以很容易地抑制它(或将其重定向到单独的文件,或其他)。 c3p0 将警告记录到名为 com.mchange.v2.c3p0.SQLWarnings 的特殊记录器中。在您使用的任何日志记录库的配置文件中,您可以通过将该记录器的级别设置为 WARNING 或更高来抑制此输出。

(有点令人困惑的是 SQLWarnings 记录在 INFO 而不是 WARNING。因为它们通常表示有关已经从中恢复的条件的信息,驱动程序作者明白大多数开发人员从未见过,所以他们不知道实质上上升到 WARNING 的级别。因此在 INFO 及以下过滤掉来自 com.mchange.v2.c3p0.SQLWarnings 的消息足以消除警告。如果您想查看负责的代码,它是here.)