我正在尝试调用具有默认(可选)参数但不传递它们的存储过程,但它不起作用。与描述的问题基本相同 here .
我的代码:
SqlParameterSource in = new MapSqlParameterSource()
.addValue("ownname", "USER")
.addValue("tabname", cachedTableName)
.addValue("estimate_percent", 20)
.addValue("method_opt", "FOR ALL COLUMNS SIZE 1")
.addValue("degree", 0)
.addValue("granularity", "AUTO")
.addValue("cascade", Boolean.TRUE)
.addValue("no_invalidate", Boolean.FALSE)
.addValue("force", Boolean.FALSE);
我得到一个异常(exception):
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Required input parameter 'PARTNAME' is missing
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:209)
其中 PARTNAME 是根据 this 的可选参数.我可以在没有 PARTNAME 参数的情况下手动运行此过程这一事实也证实了这一点。
最佳答案
Ater 放弃了这个问题,只是传递了所有参数,包括可选参数,我遇到了它无法传递 boolean 参数的问题,因为 boolean 不是 SQL 数据类型,只是 PL/SQL。
所以我目前的解决方案是 JDBC 不适合运行存储过程,这就是我解决它的方法:
jdbcTemplate.execute(
new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con) throws SQLException{
CallableStatement cs = con.prepareCall("{call sys.dbms_stats.gather_table_stats(ownname=>user, tabname=>'" + cachedMetadataTableName + "', estimate_percent=>20, method_opt=>'FOR ALL COLUMNS SIZE 1', degree=>0, granularity=>'AUTO', cascade=>TRUE, no_invalidate=>FALSE, force=>FALSE) }");
return cs;
}
},
new CallableStatementCallback() {
public Object doInCallableStatement(CallableStatement cs) throws SQLException{
cs.execute();
return null; // Whatever is returned here is returned from the jdbcTemplate.execute method
}
}
);
关于java - Spring SimpleJdbcCall 默认(可选)参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13162043/