使用ArrayDescriptor在java中创建Oracle ARRAY Type时出现问题
如果我与oracle直接连接,代码工作正常。
但是如果我通过Websphere中配置的数据源连接到数据库,则接收以下exception: –
java.sql.SQLException:DSRA9122E:com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56不包装任何类型为oracle.jdbc.driver.OracleConnection的对象。
引发此exception的代码如下: –
ArrayDescriptor desc = ArrayDescriptor.createDescriptor(PROC_IN_PARAM_ALIAS, jdbcTemplate.getDataSource().getConnection() .unwrap(OracleConnection.class));
你的错误说明了一切 –
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection@21cf8d56 不包装任何类型为oracle.jdbc.driver.OracleConnection的对象 。
createDescriptor()方法有两个参数
1.存储过程名称2.对象类型为oracle.jdbc.driver.OracleConnection
ArrayDescriptor.createDescriptor("Proc Name", oracleConnection);
jdbcTemplate.getDataSource()。getConnection()方法不返回类型为oracle.jdbc.driver.OracleConnection的对象,当您尝试解包时,它会抛出错误。
您需要执行以下操作
1.在配置文件中添加以下提到的条目。
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));