How can I read returned value from stored procedure in Spring Jdbc (without out parameters) ?
I am use Sybase ASE database.
Procedure Example:
CREATE PROCEDURE dbo.procedureA (
@a int
)
as
begin
IF EXISTS (SELECT 1 FROM dbo.T WHERE a = @a)
return 1
ELSE
return -1
end
Reference: http://www.databaseskill.com/1270151/ Key point is: SimpleJdbcCall.withReturnValue() directs the SimpleJdbcCall object to put the return value in the result map with key "RETURN_VALUE". So you can access it like (Integer)simpleJdbcCall.execute().get("RETURN_VALUE")
For Sybase, it is not necessary to declare SqlOutParameter "RETURN_VALUE"
The best approach for handle this is to use SimpleJdbcCall that it's in the Spring-Jdbc project.
With SimpleJdbcCall you can declare in and out parameters for this purpose.
You can do it something like this:
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource);
simpleJdbcCall.withCatalogName("dbo");
simpleJdbcCall.withProcedureName("procedureA ");
simpleJdbcCall.setAccessCallParameterMetaData(false);
simpleJdbcCall.declareParameters(new new SqlOutParameter("a",Types.NUMERIC));
simpleJdbcCall.execute();
More info here
Hope it helps.
This might help, although I haven't tried it myself yet;
public MyStoredProc(JdbcTemplate jdbcTemplate) {
super(jdbcTemplate, "mystoredproc");
setFunction(true);
declareParameter(new SqlOutParameter("Result", Types.NUMERIC));
declareParameter(new SqlInOutParameter("otherparam1", Types.INTEGER));
declareParameter(new SqlParameter("otherparam2", Types.INTEGER));
allowsUnusedParameters();
compile();
}
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.