public String buscarEmpleado(String codigo) { try { cn = Conexion.realizarConexion(); st = cn.createStatement(); String sql = "select chr_emplcodigo from empleado " + " where chr_emplcodigo = '" + codigo + "'"; rs = st.executeQuery(sql); while (rs.next()) { return rs.getString("chr_emplcodigo"); } } catch (ClassNotFoundException ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } catch (SQLException ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } finally { try { rs.close(); st.close(); cn.close(); } catch (Exception ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } } return null; }
public ArrayList<Empleado> listarEmpleado() { ArrayList<Empleado> emple = new ArrayList<Empleado>(); try { cn = Conexion.realizarConexion(); st = cn.createStatement(); String sql = "select * from empleado"; rs = st.executeQuery(sql); while (rs.next()) { emple.add( new Empleado( rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8))); } } catch (ClassNotFoundException ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } catch (SQLException ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } finally { try { rs.close(); st.close(); cn.close(); } catch (Exception ex) { showMessageDialog(null, ex.getMessage(), "Excepción", 0); } } return emple; }