2011-09-02 81 views
2

我有一个存储过程,只有一个整数输出参数和5个varchar输入参数,无论我尝试了什么,我似乎无法得到输出参数。我已经在db上运行了sproc,它带有数据,所以我看不到我做错了什么。simplejdbccall输出参数

有谁知道如何从simplejdbccall获取输出参数吗?

我有这样的事情:

SimpleJdbcCall simpleJdbcCall = 
     new SimpleJdbcCall(getDatasourceForEnvironment()).withProcedureName("_Get_Id").declareParameters(
      new SqlParameter("MyID", Types.VARCHAR), new SqlParameter("MySourceID", Types.VARCHAR), 
      new SqlParameter("MyLocationID", Types.VARCHAR), new SqlParameter("MyVisitID", Types.VARCHAR), 
      new SqlParameter("MyVisitDate", Types.VARCHAR)); 

    HashMap< String, String > input = new HashMap< String, String >(); 
    input.put("MyID", myObj.getMyID()); 
    input.put("MySourceID", myObj.getMySourceID()); 
    input.put("MyLocationID", myObj.getMyLocationID()); 
    input.put("MyVisitID", myObj.getMyVisitID()); 
    input.put("MyVisitDate", myObj.getMyVisitDate()); 

    System.out.println(simpleJdbcCall.execute(input)); 

回答

2

有两件事情我有错:

  1. 我连接到错误的数据库。编写更细粒度的单元 测试显示我的错误。

  2. 由于从“执行”返回的是一个映射,输出参数是 敏感。

长话短说,没有什么特别的你需要做 - 默认情况下,Spring包含输出参数。此外,MapSqlParameterSource是一种更清洁的方式去处理这些方法。

+0

当您调用函数(而不是过程)时,Spring默认不会返回OUT参数,并且期望返回值以及OUT参数。最好的方法是始终将'new SqlParameter()'定义为'new SqlInOutParameter()',这样spring就会用返回值更新map中的out参数。但不确定任何性能影响 – SashikaXP