1、sysDataSourceService是自定义的获取数据源服务
JdbcTemplate jdbcTempleDynamic = sysDataSourceService.getDataSourcePoolBySourceID(source_id);
2、使用jdbcTempleDynamic.execute调用存储过程,传入对应的所需参数
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
String sql="{call douzi_admin_v3.sp_drilling_search_v3(?,?,?,?,?,?,?)}"
resultList = (List<Map<String, Object>>) jdbcTempleDynamic.execute(
new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection con)
throws SQLException {
String sql="{call douzi_admin_v3.sp_drilling_search_v3(?,?,?,?,?,?,?)}"
CallableStatement cs=con.prepareCall(sql);
cs.setString(1, item);
cs.setString(2, target);
cs.setString(3, beginTime);
cs.setString(4, endTime);
cs.setString(5, whereSql);
cs.setString(6, timeType);
cs.setLong(7, uid);
cs.setString(8, lastkey);
return cs;
}
},new CallableStatementCallback(){
public Object doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
cs.execute();
List<Map<String, Object>> lastList = new ArrayList<Map<String,Object>>();
ResultSet rs = cs.getResultSet();
ResultSetMetaData md = rs.getMetaData(); //获得结果集结构信息,元数据
int columnCount = md.getColumnCount(); //获得列数
//将JDBC ResultSet结果集转成List
while(rs != null && rs.next()){
//LinkedHashMap按输入顺序输出
Map<String,Object> rowData = new LinkedHashMap<String,Object>();
for (int i = 1; i <= columnCount; i++) {
rowData.put(md.getColumnLabel(i), rs.getObject(i));//getColumnLabel()获取当前的字段名,getColumnName()获取数据库的字段名(别名没用)
}
lastList.add(rowData);
}
return lastList;
}
}
);