@Override public Emp get(Integer objectId) { if (conn == null) { System.err.println("No connect!!"); return null; } Emp emp = null; try { final String sql = "SELECT " + "id,lname,fname,mname,d_hire,d_fire " + "FROM DDT_EMP" + " WHERE id = ?"; PreparedStatement st = conn.prepareStatement(sql); st.setInt(1, objectId.intValue()); ResultSet rs = st.executeQuery(); while (rs.next()) { emp = new Emp(); emp.setId(rs.getInt("id")); emp.setLastName(rs.getString("lname")); emp.setFirstName(rs.getString("fname")); emp.setMiddleName(rs.getString("mname")); emp.setHireDate(rs.getDate("d_hire")); emp.setFireDate(rs.getDate("d_fire")); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } return emp; }
@Override public ArrayList<Emp> getList() { ArrayList<Emp> emps = new ArrayList<Emp>(100); if (conn == null) { System.err.println("No connect!!"); return emps; } try { Statement st = conn.createStatement(); ResultSet rs = st.executeQuery( "" + "SELECT e.id,e.lname,e.fname,e.mname,e.d_hire,e.d_fire " + "FROM DDT_EMP AS e"); while (rs.next()) { Emp emp = new Emp(); emp.setId(rs.getInt("id")); emp.setLastName(rs.getString("lname")); emp.setFirstName(rs.getString("fname")); emp.setMiddleName(rs.getString("mname")); emp.setHireDate(rs.getDate("d_hire")); emp.setFireDate(rs.getDate("d_fire")); emps.add(emp); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } return emps; }