将XML数据类型作为输入从Java传递到DB2存储过程

时间:2014-05-08 10:19:35

标签: java xml stored-procedures db2 db2-connect

我对存储过程完全是新手。 有一个要求,要传递的输入类型是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");

不确定在这里是否使用returnsResultSet以及Types.SQLXML。尝试各种格式,但不确定我的方法是否正确。

0 个答案:

没有答案