用NamedParameterJdbcTemplate的execute,PreparedStatementCallback执行带命名参数查询并返回结果..

先调用pg的函数生成cursor,再fetch all返回游标数据集.

JSONData lvRet=new JSONData();
		TransJdbcTemplate lvTj = ContextHolder.getTransJdbcTemplate();
		lvTj.doTransactionBatch(new TransCallback() {
			@Override
			public void onExecute(JdbcTemplate pvJt, NamedParameterJdbcTemplate pvNamedJt) throws Exception {
				Map lvParams=new HashMap();
				try{
					lvParams.put("date1", Util.deformatDatetime(pvsDate, "dd/MMM/yyyy"));
					lvParams.put("date2", Util.deformatDatetime(pvsDate, "dd/MMM/yyyy"));
					lvParams.put("line", pvsLine);
					lvParams.put("series_",pvsSeries);
					lvParams.put("station",pvsStation);
					pvNamedJt.execute("select * from fun_741_top10_by_date_line_series(:date1,:date2, :line,:series_,:station,'ref'); ",lvParams,
							new PreparedStatementCallback() {
								@Override
								public Boolean doInPreparedStatement(PreparedStatement ps)
										throws SQLException, DataAccessException {
									ps.execute();
									return null;
								}
							});
					lvRet.result= pvNamedJt.queryForList("fetch all in ref",(Map)null);
				}
				catch (Exception e){
					lvRet.errCode=1;
					lvRet.errMsg=e.getMessage();
					throw e;
				}
				
			}
		});
		return lvRet;

你可能感兴趣的:(java)