Olá gente;
Estou com a seguinte dúvida:
Tenho uma classe DAO com método List. Porém, esse método deve listar apenas se todos os campos tiverem registro. Se as linhas da tabela no geral estiverem preenchidas.
Tentei criar uma Exception logo depois do Execute(), mas não tive resultado. Alguem poderia me ajudar?
O código é esse:
public class MarcacaoDAO extends DAOBase{
///Atributos estáticos dos Métodos principais//////
private static String INSERT = null;
private static String SELECT = null;
public MarcacaoDAO() {
this(null);
}
public MarcacaoDAO(Connection connection) {
super(connection);
StringBuffer stringBuffer = new StringBuffer();
if(SELECT == null){
stringBuffer.delete(0, stringBuffer.length());
stringBuffer.append("{call sp_viewMCC_RPT_p25007()}");
SELECT = stringBuffer.toString();
}
}
//////Método utilizado para Listar todos os dados da Tabela////
public List listar() throws SQLException{
CallableStatement callableStatement = null;
Connection con = null;
ResultSet rs = null;
List lista = new ArrayList();
MarcacaoVO marcacaoVO = null;
try{
con = super.getConnection();
callableStatement = con.prepareCall(SELECT);
rs = callableStatement.executeQuery();
if(rs.next()){
marcacaoVO = new MarcacaoVO();
do{
/////Campos que serão Apresentados (listados)/////
/////Campos Chave/////
marcacaoVO.setCodigoMarcacao(rs.getString("CD_MCCRPT"));
marcacaoVO.setEmpresa(rs.getInt("CD_EMPGCB"));
marcacaoVO.setMatricula(rs.getInt("CD_FUN"));
////Demais Atributos////
marcacaoVO.setTipoMarcacao(rs.getString("ST_MCCRPT").charAt(0));
marcacaoVO.setViaCracha(rs.getInt("CD_MCCRPT_VIA_CCH"));
marcacaoVO.setDataMarcacao(sqlDateTOutilDate(rs.getDate("DT_MCCRPT")));
marcacaoVO.setHoraMarcacao(sqlTimeTOutilDate(rs.getTime("HR_MCCRPT")));
marcacaoVO.setEmpresaRelogio(rs.getInt("CD_EMPGCB_RLG"));
marcacaoVO.setFilialRelogio(rs.getInt("CD_FIL_RLG"));
marcacaoVO.setStatusMarcacao(rs.getString("ST_MCCRPT_RFT").charAt(0));
marcacaoVO.setTipoCartao(rs.getInt("CD_MCCRPT_TIP_CRT"));
marcacaoVO.setEnviar(rs.getString("ST_MCCRPT_ENV").charAt(0));
marcacaoVO.setErro(rs.getString("ST_MCCRPT_ERR"));
marcacaoVO.setTransmissao(rs.getString("ST_MCCRPT_TRM").charAt(0));
}while ( rs.next() );
if(rs==null){
try {
throw new Exception ("O valor "+ rs.findColumn("CD_MCCRPT")+"é nulo na base de dados");
////Bem aqui está dando erro também. Pede para remover a linha.
throw new Exception ("O valor "+ rs.findColumn("CD_EMPGCB")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("CD_FUN")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("ST_MCCRPT")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("CD_MCCRPT_VIA_CCH")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("DT_MCCRPT")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("HR_MCCRPT")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("CD_EMPGCB_RLG")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("CD_FIL_RLG")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("ST_MCCRPT_RFT")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("CD_MCCRPT_TIP_CRT")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("ST_MCCRPT_ENV")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("ST_MCCRPT_ERR")+"é nulo na base de dados");
throw new Exception ("O valor "+ rs.findColumn("ST_MCCRPT_TRM")+"é nulo na base de dados");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
lista.add(marcacaoVO);
}
}
} finally {
close(null, callableStatement, con);
}
return lista;
}
Será que estou fazendo certo? Está dando erro tambem dentro do bloco do Try / Catch.
Abraço.