简体   繁体   English

使用Spring jdbctemplate。 无法执行程序

[英]Using Spring jdbctemplate. Unable to run a procedure

I am trying to run a oracle procedure using spring jdbctemplate.I am Using the following code to run the procedure 我正在尝试使用spring jdbctemplate运行oracle过程。我正在使用以下代码运行过程

private boolean executeProcedure(jdbcTemplate JdbcTemplateTest)
{
try
{
int x = jdbcTemplateTest.update("call oracleProc()");
return true;
}
catch(Exception e)
{
 logger.error("Error While runing procedure::"+procedureName+"-"+e);
 return false;
}
}

This function running fine and it is not throwing any errors. 此函数运行良好,并且不会引发任何错误。 But i get the following problems 但是我遇到以下问题

  1. The procedure not actully executed by tha code 该程序未由Tha代码强制执行

  2. The code locks the tables, which all are used by the procedure oracleProc() 代码锁定表,所有表均由过程oracleProc()使用

Please help me to solve the issue. 请帮我解决问题。 please clarfiy what is wrong in my code. 请澄清我的代码有什么问题。

There are a number of ways to call stored procedures in Spring. 在Spring中有很多方法可以调用存储过程。

try using CallableStatementCreator, where you will be using Java's standard interface of CallableStatement. 尝试使用CallableStatementCreator,您将在其中使用Java的CallableStatement标准接口。
OR 要么

 SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
        .withSchemaName(schema)
        .withCatalogName(package)
        .withProcedureName(procedure)();
    ...
    jdbcCall.addDeclaredParameter(new SqlParameter(paramName, OracleTypes.NUMBER));
    ...
    jdbcCall.execute(callParams);

For simple procedures you may use jdbcTemplate's update method: 对于简单的过程,您可以使用jdbcTemplate的update方法:

jdbcTemplate.update("call proc (?, ?)", par1, par2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM