Pessoal, sempre usei Try-catch mas nunca dei importância se estou usando de maneira correta !!!
Seguindo um dos meus métodos… por favor, me indiquem onde posso melhorar e corrigir:
public List<Menu> listaMenuJDBC(Menu menu) throws SQLException, Exception{
ArrayList<Menu> array = new ArrayList<Menu>();
PreparedStatement sql = null;
ResultSet rs = null;
Conexao cnct = new Conexao();;
try{
cnct.conecta();
sql = cnct.conn.prepareStatement
("SELECT pai, " +
" codigo, " +
" tipo, " +
" rpad(' ',(level*5))||descricao Descricao " +
" FROM ps_menu m " +
"CONNECT BY PRIOR CODIGO = PAI START WITH PAI = 0");
rs = sql.executeQuery();
while (rs.next()){
menu = new Menu();
menu.setPai (rs.getInt(1));
menu.setCodigo (rs.getLong(2));
menu.setTipo (rs.getInt(3));
menu.setDescricao (rs.getString(4));
array.add(menu);
}
sql.close();
rs.close();
}
catch(SQLException sqle){
System.out.println(sqle.getMessage());
throw new SQLException (sqle.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
throw new Exception (e.getMessage());
}
finally{
try{
if ((cnct.conn!=null) && (!cnct.conn.isClosed())) {
cnct.conn.close();
}
}
catch(Exception e){e.printStackTrace();}
}
return array;
}
Valew.
