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/