使用 ArrayDescriptor 在 java 中创建 Oracle ARRAY 类型时出现问题
Issue while creating Oracle ARRAY Type in java using ArrayDescriptor
如果我直接与 oracle 建立连接,代码运行良好。
但是,如果我通过 Websphere 中配置的数据源连接到数据库,则会收到以下异常:-
java.sql.SQLException: DSRA9122E:
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56 does not wrap any
objects of type oracle.jdbc.driver.OracleConnection.
抛出此异常的代码如下:-
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(PROC_IN_PARAM_ALIAS, jdbcTemplate.getDataSource().getConnection()
.unwrap(OracleConnection.class));
你的错误说明了一切 -
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56 does not wrap any objects of type oracle.jdbc.driver.OracleConnection.
createDescriptor() 方法有两个参数
1.Stored 过程名称
2.An oracle.jdbc.driver.OracleConnection
类型的对象
ArrayDescriptor.createDescriptor("Proc Name", oracleConnection);
jdbcTemplate.getDataSource().getConnection() 方法不 returns 类型 oracle.jdbc.driver.OracleConnection 的对象,当您尝试解包它时,它会抛出错误。
您需要执行以下操作
1.Add 下面提到的配置文件中的条目。
<beans:property name="accessToUnderlyingConnectionAllowed" value="true"/>
2.将 java.sql.Connection
转换为 oracle.jdbc.OracleConnection
并在 createDescriptor() 方法中使用该连接对象来创建您的 oracle.sql.ArrayDescriptor 对象。
如果有人遇到类似的问题,请使用 Spring 支持的 WebSphereNativeJdbcExtractor 从 WSJdbcConnection 获取本机连接:-
//Extract the native JDBC connection from WSJdbcConnection
WebSphereNativeJdbcExtractor connection = new WebSphereNativeJdbcExtractor();
//Getting the native connection
Connection con=connection.getNativeConnection(jdbcTemplate.getDataSource().getConnection());
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(PROC_IN_PARAM_ALIAS,
con.unwrap(OracleConnection.class));
如果我直接与 oracle 建立连接,代码运行良好。
但是,如果我通过 Websphere 中配置的数据源连接到数据库,则会收到以下异常:-
java.sql.SQLException: DSRA9122E: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56 does not wrap any objects of type oracle.jdbc.driver.OracleConnection.
抛出此异常的代码如下:-
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(PROC_IN_PARAM_ALIAS, jdbcTemplate.getDataSource().getConnection()
.unwrap(OracleConnection.class));
你的错误说明了一切 -
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56 does not wrap any objects of type oracle.jdbc.driver.OracleConnection.
createDescriptor() 方法有两个参数
1.Stored 过程名称 2.An oracle.jdbc.driver.OracleConnection
类型的对象ArrayDescriptor.createDescriptor("Proc Name", oracleConnection);
jdbcTemplate.getDataSource().getConnection() 方法不 returns 类型 oracle.jdbc.driver.OracleConnection 的对象,当您尝试解包它时,它会抛出错误。
您需要执行以下操作
1.Add 下面提到的配置文件中的条目。
<beans:property name="accessToUnderlyingConnectionAllowed" value="true"/>
2.将 java.sql.Connection
转换为 oracle.jdbc.OracleConnection
并在 createDescriptor() 方法中使用该连接对象来创建您的 oracle.sql.ArrayDescriptor 对象。
如果有人遇到类似的问题,请使用 Spring 支持的 WebSphereNativeJdbcExtractor 从 WSJdbcConnection 获取本机连接:-
//Extract the native JDBC connection from WSJdbcConnection
WebSphereNativeJdbcExtractor connection = new WebSphereNativeJdbcExtractor();
//Getting the native connection
Connection con=connection.getNativeConnection(jdbcTemplate.getDataSource().getConnection());
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(PROC_IN_PARAM_ALIAS,
con.unwrap(OracleConnection.class));