springjdbctemplate调用存储过程,返回list对象

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

springjdbctemplate调⽤存储过程,返回list对象注:本⽂来源于《》
spring jdbctemplate调⽤存储过程,返回list对象
⽅法:
/**
* 调⽤存储过程
* @param spName
*/
@SuppressWarnings("unchecked")
public List<HashMap<String, Object>> executeSP(String procedure) {
//procedure = "{call WCITY2_STATISTIC.sp_uservisit_stat(?)}";
return (List<HashMap<String, Object>>) jdbcTemplate.execute(procedure,
new CallableStatementCallback() {
public Object doInCallableStatement(
CallableStatement cs) throws SQLException,
DataAccessException {
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = (ResultSet) cs.getObject(1);
while (rs.next()) {
HashMap<String, Object> dataMap = new HashMap<String, Object>();
ResultSetMetaData rsMataData = rs.getMetaData();
for (int i = 1; i <= rsMataData.getColumnCount(); i++) {
dataMap.put(rsMataData.getColumnName(i), rs
.getString(rsMataData.getColumnName(i)));
}
list.add(dataMap);
}
return list;
}
});
}
存储过程:
replace package WCITY2_STATISTIC
-- Author : ADMINISTRATOR
-- Created : 2012/10/24 9:48:34
-- Purpose :
type Ref_Cursor ref ;
--
sp_pager_stats;
--访问信息
sp_uservisit_stat(c_uservisit out Ref_Cursor);
WCITY2_STATISTIC;
replace package body WCITY2_STATISTIC
--页⾯信息
sp_pager_stats
-- cur_page as select * from OMS_WIRELESS. TEMPLATE_FILE_WORKING;
;
sp_pager_stats;
--访问信息
sp_uservisit_stat(c_uservisit out Ref_Cursor)
--定义游标
/*
cursor c_uservisit is
select t.city,ername,ername as telphone,'' as ip
from INTERFACE_ER_LOGIN_LOG t ;*/
c_uservisit
t.city, ername, ername telphone, '' ip
INTERFACE_ER_LOGIN_LOG t;
;
WCITY2_STATISTIC;
调⽤⽅法:
@SuppressWarnings("rawtypes")
String getUserVisitStat(){
//List lst=jdbcService.executeSP("");
String = "{call WCITY2_STATISTIC.sp_uservisit_stat(?)}";
List lst=spService.executeSP();
(lst!=){
System.out.println(lst.());
}
SUCCESS;
}
⾃⼰编写的代码
import java..CallableStatement;
import java..ResultSet;
import java..ResultSetMetaData;
import java..SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.JdbcTemplate;
import com.tt.pwp.framework.data.dao.DaoFactory;
import oracle.jdbc.OracleTypes;
class FuncReportTaskService {
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired
private DaoFactory daoFactory;
/**
* 调⽤存储过程
* @param spName
*/
@SuppressWarnings("unchecked")
List<HashMap<String, Object>> executeSP(String ) {
JdbcTemplate jdbcTemplate = daoFactory.getDao().getJdbcTemplate(); // = "{call WCITY2_STATISTIC.sp_uservisit_stat(?)}";
(List<HashMap<String, Object>>) jdbcTemplate.(,
new CallableStatementCallback() {
Object doInCallableStatement(
CallableStatement cs) throws SQLException,
DataAccessException {
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); cs.registerOutParameter(1, OracleTypes.);
cs.();
ResultSet rs = (ResultSet) cs.getObject(1);
(rs.()) {
HashMap<String, Object> dataMap = new HashMap<String, Object>();
ResultSetMetaData rsMataData = rs.getMetaData();
( i = 1; i <= rsMataData.getColumnCount(); i++) {
dataMap.put(rsMataData.getColumnName(i), rs
.getString(rsMataData.getColumnName(i)));
}
list.(dataMap);
}
list;
}
});
}
}。

相关文档
最新文档