1. 程式人生 > >用NamedParameterJdbcTemplate的execute,PreparedStatementCallback執行帶命名引數查詢並返回結果..

用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<String,Object> lvParams=new HashMap<String,Object>();
				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<Boolean>() {
								@Override
								public Boolean doInPreparedStatement(PreparedStatement ps)
										throws SQLException, DataAccessException {
									ps.execute();
									return null;
								}
							});
					lvRet.result= pvNamedJt.queryForList("fetch all in ref",(Map<String, ?>)null);
				}
				catch (Exception e){
					lvRet.errCode=1;
					lvRet.errMsg=e.getMessage();
					throw e;
				}
				
			}
		});
		return lvRet;