Oracle调用存储过程返回游标结果

Streamoutput 2020-01-01

/**

调用Oracle存储过程

*/

public ResultSet queryForAllJSD_NEWEST(final String hpCode, final String id) {

System.out.println("hpCode:"+hpCode+",id:"+id);
ResultSet rs = (ResultSet)this.jdbctemplate.execute("{call pro_querybcb_newest(? , ? ,?)}" , new CallableStatementCallback(){
public Object doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
cs.setString(1, hpCode) ;
cs.setString(2, id) ;
cs.registerOutParameter(3, oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
return cs.getObject(3);
}
});
return rs;
}

/**

处理返回结果

*/

ResultSet rs = dao1.queryForAllJSD_NEWEST(hpCode, id);

try {
  if (rs.next()) {
  ResultSetMetaData rsmd = rs.getMetaData();
  int i = rsmd.getColumnCount();
  System.out.println("i=" + i);
  for (int j = 1; j <= i; j++) {
    map.put(rsmd.getColumnName(j),rs.getString(j) == null ? "" : rs.getString(j));
    }
    }
  } finally {
  if (rs != null) {
    try {
      rs.close();
      } catch (SQLException e) {
  }
}

map.put("name", md.get("A4"));
map.put("idno", md.get("A7"));
map.put("Indate", md.get("A16"));
map.put("outdate", md.get("A17"));
map.put("hosno", md.get("A15"));
map.put("sick", md.get("A24"));

相关推荐