jdbctemplate调用存储过程传递数组参数

1.java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot cast to oracle.jdbc.connection

2.无效的列名称类型

[@more@]

第一个错误的解决分为两步:先把从jndi获取的数据源的connection转换为nativeConnection,转换的方法是:

con = con.getMetaData().getConnection();

然后把项目web/WEB-INF/lib/下的ojdbc14.jar删除,用web容器里的ojdbc14.jar,否则会报第一个错误

第二个错误解决:

先创建type

create type type_test as table of number;

完整调用方法:

this.getJdbcTemplate().execute(new CallableStatementCreator(){
@Override
public CallableStatement createCallableStatement(Connection con) throws SQLException {
String execuSql = "{call PKG_TEST.LIST_TEST(?)}";
CallableStatement cs = con.prepareCall(execuSql);
Object[] obj = new Object[5];
obj[0] = 0;
obj[1] = 1;
obj[2] = 2;
obj[3] = 3;
obj[4] = 4;


con = con.getMetaData().getConnection();

ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TYPE_TEST",con);
ARRAY array = new ARRAY(desc,con,obj);
cs.setArray(1,array);
return cs;
}
},new CallableStatementCallback(){
@Override
public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
cs.execute();
return "SUCCESS";
}
});

参考:

http://www.devx.me/java/the-method-for-passing-arrays-para-to-oracle.html

http://www.guj.com.br/java/134134-cast-to-oracleconnection-ajuda

http://zhang-yingjie-qq-com.iteye.com/blog/322325

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25261409/viewspace-1058443/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25261409/viewspace-1058443/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值