为什么C3p0的ComboPooledDataSource成功连接到数据库,但其克隆却没有? [英] Why does C3p0's ComboPooledDataSource successfully connect to a database, but its clone doesn't?

查看:292
本文介绍了为什么C3p0的ComboPooledDataSource成功连接到数据库,但其克隆却没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Oracle 11数据库的Tomcat 8.5.15环境中,我想实现一个处理context.xml中加密密码的数据源。我对此有麻烦,如本 StackOverflow问题

In a Tomcat 8.5.15 environment using an Oracle 11 database, I want to implement a data source that handles encrypted passwords in the context.xml. I'm having troubles with that, as described in this StackOverflow question.

为了确定潜在的问题,我简化了方案。首先,我验证了C3p0资源规范是否工作正常。

In hopes of determining the underlying problem, I simplified the scenario. First, I verified that the C3p0 resource specification worked fine.

   <Resource 
              auth="Container"
              description="MyDataSource"
              driverClass="oracle.jdbc.OracleDriver" 
              maxPoolSize="100"  
              minPoolSize="10"   
              acquireIncrement="1"  
              name="jdbc/MyDataSource"
              user="me"  
              password="mypassword"
              factory="org.apache.naming.factory.BeanFactory"
              type="com.mchange.v2.c3p0.ComboPooledDataSource"
              jdbcUrl="jdbc:oracle:thin:@mydb:1521:dev12c"
              />

工作正常。然后,基于反编译类文件,创建了 ComboPooledDataSource 的克隆:

It worked fine. Then, I created a clone of the ComboPooledDataSource, based on decompiling the class file:

public final class ComboPooledDataSourceCopy
        extends AbstractComboPooledDataSource
        implements Serializable, Referenceable {
    private static final long serialVersionUID = 1L;
    private static final short VERSION = 2;

    public ComboPooledDataSourceCopy() {
    }

    public ComboPooledDataSourceCopy(boolean autoregister) {
        super(autoregister);
    }

    public ComboPooledDataSourceCopy(String configName) {
        super(configName);
    }

    private void writeObject(ObjectOutputStream oos) throws IOException {
        oos.writeShort(2);
    }

    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
        short version = ois.readShort();
        switch(version) {
            case 2:
                return;
            default:
                throw new IOException("Unsupported Serialized Version: " + version);
        }
    }
}

我创建了修订的资源规范使用克隆的类:

I created a revised resource specification using the cloned class:

   <Resource 
              auth="Container"
              description="MyDataSource"
              driverClass="oracle.jdbc.OracleDriver" 
              maxPoolSize="100"  
              minPoolSize="10"   
              acquireIncrement="1"  
              name="jdbc/MyDataSource"
              user="me"  
              password="mypassword"
              factory="org.apache.naming.factory.BeanFactory"
              type=type="com.mycompany.ComboPooledDataSourceCopy"
              jdbcUrl="jdbc:oracle:thin:@mydb:1521:dev12c"
              />

当我尝试使用此规范连接到数据库时,连接尝试失败。

When I try to connect to the database using this specification, the connection attempt fails.

...
Caused by: java.sql.SQLException: com.mchange.v2.c3p0.impl.NewProxyConnection@6950dfda
[wrapping: oracle.jdbc.driver.T4CConnection@765426dd]
is not a wrapper for or implementation of oracle.jdbc.OracleConnection
    at com.mchange.v2.c3p0.impl.NewProxyConnection.unwrap(NewProxyConnection.java:1744)
    at org.jaffa.security.JDBCSecurityPlugin.executeStoredProcedure(JDBCSecurityPlugin.java:117)
    ... 67 more

为什么克隆尝试无法连接?

Why does the clone attempt fail to connect?

更新:

在我们本地DBA的帮助下,我们能够审核我的连接尝试。看来我们已经成功连接到数据库并登录了。基于此,听起来问题可能出在代码如何处理数据库的响应上,而不是在我们的请求生成中。

With assistance from our local DBA, we’ve been able to audit my connection attempts. It appears that we are successfully connecting to the database and logging in. Based on this, it sounds like the problem may be in how the code is handling the database’s response, rather than in our request generation.

推荐答案

该错误是类加载问题的结果,该问题是从多个jar加载Oracle类(%CATALINA_HOME%\ lib\ojdbc7-12.1.0.2.0.jar %CATALINA_HOME%\webapps\my-webapp-1.0.0\WEB-INF\lib\ classojdbc7-12.1.0.2.0.jar )。当我删除%CATALINA_HOME%\webapps\my-webapp-1.0.0\WEB-INF\lib\ojdbc7-12.1.0.2.0.jar ,我的问题就解决了。

The error was a result of a class loading problem, where the Oracle classes were being loaded from multiple jars (%CATALINA_HOME%\lib\ojdbc7-12.1.0.2.0.jar and %CATALINA_HOME%\webapps\my-webapp-1.0.0\WEB-INF\lib\ojdbc7-12.1.0.2.0.jar) by different class loaders. When I deleted %CATALINA_HOME%\webapps\my-webapp-1.0.0\WEB-INF\lib\ojdbc7-12.1.0.2.0.jar, my problem went away.

这些来源( 1 2 3 )对此进行讨论

These sources (1, 2, 3) discuss this in more detail.

这篇关于为什么C3p0的ComboPooledDataSource成功连接到数据库,但其克隆却没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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