[英]How read returned value from stored procedure in Spring Jdbc (without out parameters in procedure)
How can I read returned value from stored procedure in Spring Jdbc (without out parameters) ? 如何从Spring Jdbc中的存储过程中读取返回的值(没有参数)?
I am use Sybase ASE database. 我正在使用Sybase ASE数据库。
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". 参考: http ://www.databaseskill.com/1270151/关键点是:SimpleJdbcCall.withReturnValue()指示SimpleJdbcCall对象使用键“ RETURN_VALUE”将返回值放入结果映射中。 So you can access it like (Integer)simpleJdbcCall.execute().get("RETURN_VALUE")
因此,您可以像(Integer)simpleJdbcCall.execute()。get(“ RETURN_VALUE”)一样访问它
For Sybase, it is not necessary to declare SqlOutParameter "RETURN_VALUE" 对于Sybase,不需要声明SqlOutParameter“ RETURN_VALUE”
The best approach for handle this is to use SimpleJdbcCall that it's in the Spring-Jdbc project. 解决此问题的最佳方法是使用Spring-Jdbc项目中的SimpleJdbcCall 。
With SimpleJdbcCall you can declare in and out parameters for this purpose. 使用SimpleJdbcCall可以为此目的声明输入和输出参数。
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();
Hope it helps. 希望能帮助到你。
This might help, although I haven't tried it myself yet; 尽管我自己还没有尝试过,但这可能会有所帮助。
http://forum.spring.io/forum/spring-projects/data/114859-return-value-of-stored-procs-using-storedprocedure-class-and-not-simplejdbccall http://forum.spring.io/forum/spring-projects/data/114859-return-value-of-stored-procs-using-storedprocedure-class-and-not-simplejdbccall
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.