public static List getProvice(final Map paramMap) throws Exception
{
try {
List list = template.execute(new ConnectionCallback()
{
@Override
public List doInConnection(Connection conn)
throws SQLException, DataAccessException
{
CallableStatement call = conn.prepareCall("call p_get_province(?,?,?,?,?,?)");
call.setString("iv_code", paramMap.get("Report_Id"));
if (StringUtils.isNotBlank(paramMap.get("Role"))) {
call.setInt("in_staff_role", Integer.parseInt(paramMap.get("Role")));
} else {
call.setString("in_staff_role", null);
}
if (StringUtils.isNotBlank(paramMap.get("ProvinceId"))) {
call.setInt("in_provincial_id", Integer.parseInt(paramMap.get("ProvinceId")));
} else {
call.setString("in_provincial_id", null);
}
call.setString("iv_m_id", paramMap.get("mId"));
call.registerOutParameter("ocur_exec_status", OracleTypes.CURSOR);
call.registerOutParameter("ocur_province", OracleTypes.CURSOR);
DataSourceUtils.applyTimeout(call, template.getDataSource(), 30);// 30秒超时
call.execute();
ResultSet rs = (ResultSet) call.getObject("ocur_exec_status");
int status = 0;
String info = "";
while (rs.next()) {
status = rs.getInt("Exec_Status");
info = rs.getString("Exec_info");
}
rs.close();
if (status == 0) {
List provinceList = new ArrayList();
ResultSet rs1 = (ResultSet) call.getObject("ocur_province");
while (rs1.next()) {
MyObject mo = new MyObject();
mo.setValue(rs1.getString("province_value"));
mo.setText(rs1.getString("province"));
provinceList.add(mo);
}
rs1.close();
return provinceList;
} else {
return null;
}
}
});
return list;
}
catch (DataAccessException e) {
throw e;
}
catch (Exception e) {
throw e;
}
}
2.存储过程中有自定义struct时
Struct类型声明:
CREATE OR REPLACE TYPE header_struct as object
(
w_id varchar2(8),
a_time date,
b_time date,
token varchar2(20)
)
create or replace type Report_List as varray(2000) of REPORT_STRUCT
create or replace type REPORT_STRUCT as object(
REQUEST_ID NUMBER(10),
STATUS NUMBER(3),
FILENAME VARCHAR2(200),
DESCRIPTION VARCHAR2(201),
REQUESTDATETIME DATE
)
CREATE OR REPLACE TYPE ERROR_MESSAGE_STRUCT as object
(
error_type number(3),
error_code number(10),
message varchar2(255)
)
存储过程声明:
CREATE OR REPLACE PROCEDURE get_report_list
(
iv_header IN header_struct,
iv_function_name IN VARCHAR2,
iv_report_date IN DATE,
ov_report_list OUT report_list,
ov_error_message OUT error_message_struct
)
Java代码写法:
public static Object[] getReportResultList(final Header header,
final String functionName, final Date dateTime)
{
try {
return template.execute(new ConnectionCallback