在使用Oracle 11数据库的Tomcat 8.5.15环境中,我想实现一个处理context.xml中加密密码的数据源。我遇到了麻烦,如StackOverflow question所述。
为了确定潜在的问题,我简化了方案。首先,我验证了C3p0资源规范工作正常。
<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
的克隆:
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);
}
}
}
我使用克隆类创建了修订的资源规范:
<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"
/>
当我尝试使用此规范连接到数据库时,连接尝试失败。
...
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
为什么克隆尝试无法连接?
更新:
在我们当地的DBA的帮助下,我们已经能够审核我的连接尝试。看来我们已成功连接到数据库并登录。基于此,听起来问题可能在于代码如何处理数据库的响应,而不是在我们的请求生成中。