MK.*_*MK. 10 java spring stored-procedures jdbc
我试图调用一个存储过程,该存储过程具有默认(可选)参数而不传递它们并且它不起作用.基本上与此处描述的问题相同.
我的代码:
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);
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Required input parameter 'PARTNAME' is missing
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:209)
Run Code Online (Sandbox Code Playgroud)
当零件名称是根据一个可选的参数此.我也可以通过手动运行这个带有PARTNAME参数的过程来确认.
Ater 放弃了这个问题,只传递了所有参数,包括可选参数,我遇到了无法传递布尔参数的情况,因为布尔不是 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
}
}
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7259 次 |
| 最近记录: |