0

我完全是存储过程的新手。有一个要求,例如要传递的 Input 类型是 XML 数据类型到 DB2 存储过程并作为 ResultSet 输出。

//存储过程:

  CREATE PROCEDURE GetGrpInfo (IN inpdoc XML)
  DYNAMIC RESULT SETS 1
  P1: BEGIN

  Declare tin VARCHAR(9);
  Declare max_records INT;
  Declare start_index INT;

        DECLARE rcount INT;
        DECLARE total_count INT;
        ..........
        ..........

//Java代码:

    private final static String myXML = "inpdoc";
    private final static String SpOutput = "RESULT";

    @Autowired
     public void setDataSource(DataSource db2DataSource) {
        String procedureName = "schemaname.GetGrpInfo";
           this.db2DataSource = db2DataSource;
            this.jdbcCall =  new SimpleJdbcCall(this.db2DataSource)
            .withProcedureName(procedureName)
            .withoutProcedureColumnMetaDataAccess()
            .useInParameterNames(myXML)
            .declareParameters(new SqlParameter(myXML, Types.SQLXML)) 
            .returningResultSet("GroupInfo", new BeanPropertyRowMapper<GroupInfo>(){
                public GroupInfo mapRow(ResultSet rs, int rowNum)
                throws SQLException {
                    GroupInfo gInfo =  new GroupInfo();
                    gInfo.setGroupId(rs.getString("GroupID"));
                    gInfo.setGroupName(rs.getString("GroupName"));
                    gInfo.setGroupTaxId(rs.getString("GroupTIN"));
                    return gInfo;
                }
            });
        }

      String input1 =  "<Input><TIN>"+tin+"</TIN><MaxRecords>"+max_records+" </MaxRecords><StartIndex>"+start_index+"</StartIndex></Input>";
      SqlParameterSource in = new MapSqlParameterSource().addValue(myXML, input1);
      Map result = jdbcCall.execute(in);
      return (String)result.get("GroupInfo");

不知道returnResultSet的使用在这里是否擅长,Types.SQLXML也是如此。尝试了各种格式,但不确定我的方法是否正确。

4

0 回答 0