SimpleJdbcCall: get result of Microsoft/Sybase stored procedure call
-
12-10-2019 - |
Pergunta
I've a Microsoft and Sybase stored procedures that return result as "return @value". I need to read the value from Java via SimpleJdbcCall.
Is it possible?
Solução
Use the SqlOutPutParameters :)
Here is an example :
SimpleJdbcCall countryProcedure = new SimpleJdbcCall(dataSource)
.withoutProcedureColumnMetaDataAccess()
.withProcedureName(procedureName)
.declareParameters(new SqlOutParameter("RETURNCODE", Types.INTEGER))
.declareParameters(new SqlOutParameter("RETURNMSG", Types.VARCHAR));
Map result = countryProcedure.execute();
System.out.println("RETURNCODE: " + result.get("RETURNCODE"));
System.out.println("RETURNMSG: " + result.get("RETURNMSG"));
Edit : I looked at it and there is a simpler way. Use the WithReturnValue() on your SimpleJdbcCall and the return value will be stored in the return Map under the "return" key.
Outras dicas
Spring has supported stored procedures nicely since 2.x:
http://static.springsource.org/spring/docs/2.0.x/reference/jdbc.html
These should be able to sort you out.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow