Try Catch não funciona como esperado

0 respostas
webservicejavarest
Paulo_Velosa

Pessoal,

Tenho a seguinte função getPendingInvc que faz conexão com o DB2. Em momentos de erro de conexão, essa função não é tratada corretamente pela função checkInvoice. Por algum motivo o erro de conexão da chamada não cai no Catch.

getPendingInvc
@Override
public int getPendingInvc(long ascRegister, int colnCmpgnYr, int colnCmpgnNr,
int colnOrdId) throws Exception {

// TODO Auto-generated method stub
	s_logger.info(">>> Entering into  AccountabilityDAOForDB2Impl.getPendingInvc() method >>> ");
	List<Integer> count = new ArrayList<Integer>();
	//String dbOwner =  (String)jndiTemplate.lookup("java:comp/env/DB2_OWNER"); 
	try
	{
	
	String dbOwner =  (String)jndiTemplate.lookup("DB2_OWNER"); 
	s_logger.info(">>>DB2 OWner >>> "+dbOwner);
	String varSql =  "select count(*) from "+dbOwner+".pnddbtv" +
	 " where rep_nr = " + Integer.parseInt(AccountabilityUtils.formatCod(ascRegister,8).substring(0,5)) +
	 " and rep_asc_nr = " + Integer.parseInt(AccountabilityUtils.formatCod(ascRegister,8).substring(5,8)) +
	 " and ord_id_nr = " + colnOrdId + //CL23251 - Defect Fix 570
	 " and cmpgn_yr_nr = " + colnCmpgnYr + //CL23251 - Defect Fix 570
	 " and cmpgn_nr = " + colnCmpgnNr + //CL23251 - Defect Fix 570
	 " and (dbt_val_amt + ADJSTMT_VAL_AMT - tot_pymts_val_amt) > 0";

	 s_logger.info(" E o sql pra consulta é or  Query  :: " +varSql);		 
	  count = jdbcTemplateForDB2.query(varSql.toString() ,new IntegerRowMapper());		 
	 s_logger.info(" E o retorno em qty é or record size :: " +count.size());
	 s_logger.info(">>> Leaving from AccountabilityDAOForDB2Impl.getPendingInvc() method >>> ");
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
		System.out.println("Exception :: "+ex.getMessage());
	}
	return getColumnCount(count);

}
<strong><em>checkInvoice</em></strong>

try {

System.out.println(“accountbailityDB2DAO.getPendingInvc”);

count= accountbailityDB2DAO.getPendingInvc(ascRegister, colnCmpgnYr, colnCmpgnNr, colnOrdId);
} catch (Exception  e) {
			e.printStackTrace();
			s_logger.error("Error in AccountabilityDAOImpl.checkInvoice() and the message is ",e  );

			if (e.getMessage() == null || e.getMessage().indexOf( "timed out" ) >=0 ) {
				return dbOwnerResult = "timed out";
			}else {
				return dbOwnerResult = "connection error";
			}

		}

		s_logger.info("E o retorno em qty é:"  + count);
					
			if(count > 0) //Se estive pendente
			{
				dbOwnerResult = "true";
			}	
	
	
			s_logger.info("E o retorno do método é:" + dbOwnerResult);

	s_logger.info("<<< Leaving from  AccountabilityDAOImpl.checkInvoice() >>>"  );

	return dbOwnerResult;
}
Criado 5 de outubro de 2018
Respostas 0
Participantes 1