我有一个存储过程,其中包含一个输入和一个输出参数。输入参数由SqlInOutParameter定义,并由SqlOutParameter输出。使用ojdbc6一切正常,但是使用ojbc8,它会在测试中给出断言异常。由于我没有在我的应用程序中启用断言,因此在那里工作正常。
以下是存储过程类的声明
class CustomStoredProcedure extends org.springframework.jdbc.object.StoredProcedure {
private static final String PROCEDURE_NAME = "MY_PROCEDURE";
private static final String INPUT_PARAM_1= "INPUT_PARAM_1";
public static final String OUTPUT_PARAM_1 = "OUTPUT_PARAM_1";
public CustomStoredProcedure (DataSource dataSource) {
super(dataSource, PROCEDURE_NAME);
declareParameter(new SqlInOutParameter(INPUT_PARAM_1, OracleTypes.NUMERIC));
declareParameter(new SqlOutParameter(OUTPUT_PARAM_1 , OracleTypes.CURSOR));
compile();
}
}
以下是我获得的异常追踪
Caused by: java.lang.AssertionError: Length not positive
at oracle.jdbc.driver.NumberCommonAccessor.getBigDecimal(NumberCommonAccessor.java:2330)
at oracle.jdbc.driver.NumberCommonAccessor.getObject(NumberCommonAccessor.java:3075)
at oracle.jdbc.driver.T4CVarnumAccessor.getObject(T4CVarnumAccessor.java:248)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1753)
at oracle.jdbc.driver.OracleCallableStatementWrapper.getObject(OracleCallableStatementWrapper.java:639)
at sun.reflect.GeneratedMethodAccessor226.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
at com.sun.proxy.$Proxy597.getObject(Unknown Source)
at net.ttddyy.dsproxy.listener.OracleOutputParameterLogEntryCreator.getOutputParameters(OracleOutputParameterLogEntryCreator.java:65)
at net.ttddyy.dsproxy.listener.OracleOutputParameterLogEntryCreator.getOutputParametersInDefaultFormat(OracleOutputParameterLogEntryCreator.java:46)
at net.ttddyy.dsproxy.listener.OracleOutputParameterLogEntryCreator.getLogEntry(OracleOutputParameterLogEntryCreator.java:25)
at net.ttddyy.dsproxy.listener.AbstractQueryLoggingListener.getEntry(AbstractQueryLoggingListener.java:32)
at net.ttddyy.dsproxy.listener.AbstractQueryLoggingListener.afterQuery(AbstractQueryLoggingListener.java:24)
at net.ttddyy.dsproxy.proxy.PreparedStatementProxyLogic.invoke(PreparedStatementProxyLogic.java:185)
at net.ttddyy.dsproxy.proxy.jdk.CallableStatementInvocationHandler.invoke(CallableStatementInvocationHandler.java:29)
at com.sun.proxy.$Proxy598.execute(Unknown Source)
at org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1144)
at org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1141)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1089)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1141)
at org.springframework.jdbc.object.StoredProcedure.execute(StoredProcedure.java:123)
以下是参考的样本存储过程
create or replace Procedure MY_PROCEDURE
( INPUT_PARAM_1 IN NUMBER
,OUTPUT_PARAM_1 OUT NUMBER
) AS
BEGIN
SELECT INPUT_PARAM_1 + 1 INTO OUTPUT_PARAM_1 FROM dual;
END MY_PROCEDURE;
我使用的罐子是ojdbc8-12.2.0.1.0和spring-jdbc-4.3.13
我尝试扩展ResultSetSupportingSqlParameter来创建我自己的SqlInParameter,该异常失败。
我也查看了Spring的其他SqlParameter类,但是没有只适用于Oracle Stored过程的IN参数的类。帮助我指出我在这里做错了什么。
答案 0 :(得分:0)
在存储过程的参数中使用org.springframework.jdbc.core.SqlParameter解决了这个问题。