查询存储过程返回结果集

存储过程

CREATE OR REPLACE PACKAGE PKG_QUALITYCONTROL IS
  TYPE retcursor IS REF CURSOR;
  PROCEDURE GET_QUALITYCONTROL(v_encounterid in nvarchar2,
                                   v_patientid   in nvarchar2,
                                   outcurse      IN OUT retcursor);
END;
CREATE OR REPLACE PACKAGE BODY PKG_QUALITYCONTROL IS
  PROCEDURE GET_QUALITYCONTROL(v_encounterid in nvarchar2,
                                   v_patientid   in nvarchar2,
                                   outcurse      IN OUT retcursor) IS
  begin
    OPEN outcurse FOR
      select fm.formid,
             fm.formtype,
             fm.formname,
             fm.formurl,
             case
               when exists (select 1
                       from form f
                      where f.states = 'N'
                        and f.formtype = fm.formtype
                        and f.encid = v_encounterid
                        and f.patientid = v_patientid) then
                '暂存'
               when exists (select 1
                       from form f
                      where f.states = 'Y'
                        and f.formtype = fm.formtype
                        and f.encid = v_encounterid
                        and f.patientid = v_patientid) then
                '是'
               else
                '否'
             end formtemp
        from form_menu fm
       where fm.formtype in ('Form1',
                             'Form2',
                             'Form3',
                             'Form4',
                             'Form5',
                             'Form6',
                             'Form7');
    return;
  end;
END;

此处只显示部分SQL,因为业务复杂决定采用存储过程

java代码部分

public List<String[]> getFormMenuList(String encid, String patientid) throws ControllerException {
		String me = getClass().getName() + ".getFormMenuList()";
		List<String[]> ls = new ArrayList<String[]>();
		Connection conn = null;
		CallableStatement cstmt = null;
		ResultSet rs = null;
		String sql = "{call PKG_MANAGEJOBS.GET_QUALITYCONTROL(?, ?, ?)}";
		try {
			conn = getNisJdbcConnection();
			cstmt = conn.prepareCall(sql);
		    cstmt.setString(1, encid);
		    cstmt.setString(2, patientid);
		    cstmt.registerOutParameter(3, oracle.jdbc.OracleTypes.CURSOR); //outcurse
		    cstmt.execute();
		    rs = (ResultSet) cstmt.getObject(3);
			String[] array = null;
			while (rs.next()) {
				array = new String[7];
				array[0] = rs.getString("formid");
				array[1] = rs.getString("formtype");
				array[2] = rs.getString("formname");
				array[3] = rs.getString("formurl");
				array[4] = rs.getString("formtemp");
				ls.add(array);
			}
		} catch (Throwable e) {
			throw new ControllerException("{0}:获取出院病人记录列表", new String[] { me }, e);
		} finally {
			closeConnection(conn, cstmt, rs);
		}
		return ls;
	}

猜你喜欢

转载自blog.csdn.net/u011410116/article/details/84935938
今日推荐