Fala galera estou tento problemas em uma querry onde o resultSet aparentemente esta retornando nulo, porem copiei exatamente a query do console e fiz o select no banco e tenho resultados .
Alguem saberia qual o problema segue a funcao
o Objeto esta sempre retornando nulo
public ErosionFactorVO getErosionFactorVO(Integer idContract, Long idPortfolio, Integer dtBase, Integer idInstrument, Integer dtPosi, Connection conn) throws SQLException
{
ErosionFactorVO erosionFactorVo = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try
{
String sql = "WITH tb_prev_event AS (" +
" SELECT tb_dist_certificate_quote_erosion_factor.id_contract,"+
" tb_dist_certificate_quote_erosion_factor.id_portfolio," +
" tb_dist_certificate_quote_erosion_factor.id_instrument,"+
" tb_dist_certificate_quote_erosion_factor.dt_base,"+
" tb_dist_certificate_quote_erosion_factor.dt_event,"+
" tb_dist_certificate_quote_erosion_factor.id_factor_type,"+
" tb_dist_certificate_quote_erosion_factor.qtd_quotes_reference,"+
" tb_dist_certificate_quote_erosion_factor.qtd_quotes_erosion,"+
" tb_dist_certificate_quote_erosion_factor.vl_rentability,"+
" tb_dist_certificate_quote_erosion_factor.is_factor_executed,"+
" tb_dist_certificate_quote_erosion_factor.dt_reference AS dt_prev_event,"+
" COALESCE(tb_as_portfolio_market_price.vl_price, tb_as_portfolio_market_price.vl_price_valemobi) AS vl_price_prev_event,"+
" tb_dist_certificate_quote_erosion_factor.vl_iof_factor_basis"+
" FROM tb_as_portfolio_market_price"+
" INNER JOIN tb_dist_certificate_quote_erosion_factor"+
" ON (tb_dist_certificate_quote_erosion_factor.id_contract = tb_as_portfolio_market_price.id_contract"+
" AND tb_dist_certificate_quote_erosion_factor.id_portfolio = tb_as_portfolio_market_price.id_portfolio"+
" AND tb_dist_certificate_quote_erosion_factor.id_instrument = tb_as_portfolio_market_price.id_instrument"+
" AND tb_dist_certificate_quote_erosion_factor.dt_reference = tb_as_portfolio_market_price.dt_trade"+
" AND tb_dist_certificate_quote_erosion_factor.dt_reference = (SELECT MAX(dt_reference) FROM tb_dist_certificate_quote_erosion_factor AS tb_prev_fact"+
" WHERE"+
" tb_prev_fact.id_contract = tb_dist_certificate_quote_erosion_factor.id_contract"+
" AND tb_prev_fact.id_portfolio = tb_dist_certificate_quote_erosion_factor.id_portfolio"+
" AND tb_prev_fact.id_instrument = tb_dist_certificate_quote_erosion_factor.id_instrument"+
" AND tb_prev_fact.dt_base = tb_dist_certificate_quote_erosion_factor.dt_base"+
" AND dt_reference <= ?))"+
" WHERE tb_dist_certificate_quote_erosion_factor.id_contract = ?"+
" AND tb_dist_certificate_quote_erosion_factor.id_portfolio = ?"+
" AND tb_dist_certificate_quote_erosion_factor.id_instrument = ?"+
" AND tb_dist_certificate_quote_erosion_factor.dt_base = ?"+
" AND tb_dist_certificate_quote_erosion_factor.vl_ir_factor > 0"+
" AND tb_dist_certificate_quote_erosion_factor.is_factor_executed)"+
" SELECT tb_as_trade_custody_posi_day.id_contract, "+
" tb_as_trade_custody_posi_day.id_instrument,"+
" tb_as_trade_custody_posi_day.id_portfolio, "+
" tb_as_trade_custody_posi_day.id_custodian,"+
" tb_as_trade_custody_posi_day.id_operation, "+
" tb_prev_event.dt_event,"+
" tb_as_trade_custody_posi_day.vl_price, "+
" tb_prev_event.id_factor_type,"+
" tb_prev_event.qtd_quotes_reference, "+
" tb_prev_event.qtd_quotes_erosion, "+
" tb_as_trade_custody_posi_day.dt_posi, "+
" tb_as_trade_custody_posi_day.realized,"+
" tb_prev_event.vl_rentability,"+
" tb_prev_event.is_factor_executed,"+
" COALESCE(tb_as_trade_custody_posi_day.dt_base, dt_prev_event) AS dt_prev_event,"+
" COALESCE(vl_price_prev_event, tb_as_trade_custody_posi_day.vl_price) AS vl_price_prev_event,"+
" COALESCE(tb_prev_event.vl_iof_factor_basis,0) AS vl_iof_factor_basis"+
" FROM tb_as_trade_custody_posi_day"+
" LEFT JOIN tb_prev_event"+
" ON (tb_prev_event.id_contract = tb_as_trade_custody_posi_day.id_contract"+
" AND tb_prev_event.id_portfolio = tb_as_trade_custody_posi_day.id_portfolio"+
" AND tb_prev_event.id_instrument = tb_as_trade_custody_posi_day.id_instrument"+
" AND tb_prev_event.dt_base = tb_as_trade_custody_posi_day.dt_base)"+
" WHERE"+
" tb_as_trade_custody_posi_day.id_contract = ?"+
" AND tb_as_trade_custody_posi_day.id_portfolio = ?"+
" AND tb_as_trade_custody_posi_day.id_instrument = ?"+
" AND tb_as_trade_custody_posi_day.dt_base = ?"+
" AND tb_as_trade_custody_posi_day.dt_posi = ?";
stmt = conn.prepareStatement(sql);
int i = 1 ;
stmt.setInt(i++, dtPosi);
stmt.setInt(i++, idContract);
stmt.setLong(i++, idPortfolio);
stmt.setLong(i++, idInstrument);
stmt.setLong(i++, dtBase);
stmt.setLong(i++, idContract);
stmt.setLong(i++, idPortfolio);
stmt.setLong(i++, idInstrument);
stmt.setLong(i++, dtBase);
stmt.setInt(i, dtPosi);
log.debug("querryprev {}", stmt);
log.debug("getErosionFactorVO = " + stmt);
rs = stmt.executeQuery();
if (rs.next())
{
erosionFactorVo = new ErosionFactorVO();
erosionFactorVo.setIdContrat(rs.getInt("id_contract"));
erosionFactorVo.setIdInstrument(rs.getInt("id_instrument"));
erosionFactorVo.setIdPortifolio(rs.getInt("id_portfolio"));
erosionFactorVo.setIdCustodian(rs.getInt("id_custodian"));
erosionFactorVo.setDtReference(rs.getInt("id_operation"));
erosionFactorVo.setDtBase(rs.getInt("dt_event"));
erosionFactorVo.setVlPrice(rs.getBigDecimal("vl_price"));
erosionFactorVo.setDtBase(rs.getInt("id_factor_type"));
erosionFactorVo.setQtdQuotesReference(rs.getBigDecimal("qtd_quotes_reference"));
erosionFactorVo.setQtdQuotesErosion(rs.getBigDecimal("qtd_quotes_erosion"));
erosionFactorVo.setDtPosi(rs.getInt("dt_posi"));
erosionFactorVo.setIsFactorExecuted(rs.getBoolean("realized"));
erosionFactorVo.setVlRentability(rs.getBigDecimal("vl_rentability"));
erosionFactorVo.setIsFactorExecuted(rs.getBoolean("is_factor_executed"));
erosionFactorVo.setDtBase(rs.getInt("dt_base"));
erosionFactorVo.setIdFactorType(rs.getInt("id_factor_type"));
erosionFactorVo.setVlIofFactor(rs.getBigDecimal("vl_iof_factor"));
erosionFactorVo.setVlIrFactor(rs.getBigDecimal("vl_ir_factor"));
erosionFactorVo.setDtPrevEvent(rs.getInt("dt_prev_event"));
erosionFactorVo.setVlPricePrevEvent(rs.getBigDecimal("vl_price_prev_event"));
erosionFactorVo.setIofBasisFactor(rs.getBigDecimal("vl_iof_factor_basis"));
}
} finally
{
closePreparedStatement(stmt);
closeResultSet(rs);
}
return erosionFactorVo;
}