Spring JdbcTemplate和oracle arrayofnumber
我在解决方案中使用Spring和Oracle数据库,我需要执行脚本Spring JdbcTemplate和oracle arrayofnumber,spring,oracle,spring-jdbc,Spring,Oracle,Spring Jdbc,我在解决方案中使用Spring和Oracle数据库,我需要执行脚本 select count(1) from ELEMENTS, table(cast(? as arrayofnumbers)) session_ids where root_session_id in session_ids.VALUE 但是我在传递输入参数时遇到了一个问题 我尝试将BigInteger的列表或数组传递到 JdbcTemplate.
select count(1) from ELEMENTS, table(cast(? as arrayofnumbers)) session_ids
where root_session_id in session_ids.VALUE
但是我在传递输入参数时遇到了一个问题
我尝试将BigInteger的列表或数组传递到
JdbcTemplate.queryForObject("select count(1) from ELEMENTS, table(cast(? as arrayofnumbers)) session_ids
where root_session_id in session_ids.VALUE", Integer.class, INPUT_PARAMS)
但有一个例外:
java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8861)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8338)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9116)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:9093)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:234)
at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:357)
有人有同样的问题吗
编辑:
忘记描述数组编号。它是自定义类型:
TYPE arrayofnumbers as table of number(20)
找到解决方案:
final BigInteger[] ids = new BigInteger[]{BigInteger.valueOf(9137797712513092132L)};
int count = jdbc.query("select count(1) from NC_DATAFLOW_ELEMENTS\n" +
" where root_session_id in (select /*+ cardinality(t 10) */ * from table(cast (? as arrayofnumbers)) t)"
, new PreparedStatementSetter() {
public void setValues(PreparedStatement preparedStatement) throws SQLException {
Connection conn = preparedStatement.getConnection();
OracleConnection oraConn = conn.unwrap(OracleConnection.class);
oracle.sql.ARRAY widgets = oraConn.createARRAY("ARRAYOFNUMBERS", ids);
preparedStatement.setArray(1, widgets);
}
}, new ResultSetExtractor<Integer>() {
public Integer extractData(ResultSet resultSet) throws SQLException, DataAccessException {
resultSet.next();
return resultSet.getInt(1);
}
});
out.println(count);
应该注意,数组ARRAYOFNUMBER的类型应该是大写的我不知道您是否可以用stanadart jdbc实现这一点。我认为您可以使用oracle jdbc驱动程序中的类,它有数组和其他与oracle类型相对应的类。另外,arrayofnumber听起来不是一个有效的强制转换类型…请在主注释中找到arrayofnumber类型的描述