简体   繁体   中英

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

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

  2. The code locks the tables, which all are used by the procedure 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.

try using CallableStatementCreator, where you will be using Java's standard interface of 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("call proc (?, ?)", par1, par2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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