/* * fetch for a single pid */ public void fetch(String pid) throws DNFException { DB db = new DB(); try { Connection conn = db.openConnection(); Statement stm = conn.createStatement(); String sql = "SELECT * FROM " + TABLE_NAME + " where pid='" + pid + "'"; // join user_roles on ResultSet rset = stm.executeQuery(sql); while (rset.next()) { this.pid = rset.getString("pid"); this.firstName = rset.getString("first_name"); this.lastName = rset.getString("last_name"); this.addr1 = rset.getString("addr1"); this.addr2 = rset.getString("addr2"); this.email = rset.getString("email"); this.birth = rset.getString("birth"); this.phone = rset.getString("phone"); this.cell = rset.getString("cell"); this.fam_role = rset.getString("fam_role"); this.familypid = rset.getString("fam_pid"); this.mem_role = rset.getString("mem_role"); this.middleName = rset.getString("middle_name"); this.has_comp = rset.getString("has_comp"); } rset.close(); stm.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } }
public void store() { com.soward.db.DB db = new com.soward.db.DB(); Connection conn; Statement stm = null; try { conn = db.openConnection(); stm = conn.createStatement(); if (this.assertStorable()) { // check to see that the family pid is set if so do nothing, else // create new family entry and get key for familypid. // System.out.println("FamPid: "+familypid); if (!StringUtil.isSet(this.familypid)) { Family newFamily = new Family(); String famName = ""; // if pid not set, this is a new family. famName = lastName + "_" + firstName; this.familypid = newFamily.saveId(famName, getMem_role().equals(MemberDomain.ELDER)); } // System.out.println("FamPid: "+familypid); // check to see if this is an update // by checking for a mempid // if memberpid exists, do update if (!hasPid()) { String sql = "insert into " + TABLE_NAME + " " + COL_NAMES + "values(" + null + "," + "'" + (firstName.replaceAll("'", "'")) + "'" + "," + "'" + (lastName.replaceAll("'", "'")) + "'" + "," + "'" + (addr1.replaceAll("'", "'")) + "'" + "," + "'" + (addr2.replaceAll("'", "'")) + "'" + "," + "'" + (email.replaceAll("'", "'")) + "'" + "," + "'" + (birth.replaceAll("'", "'")) + "'" + "," + "'" + (cell.replaceAll("'", "'")) + "'" + "," + "'" + (fam_role.replaceAll("'", "'")) + "'" + "," + "'" + (familypid.replaceAll("'", "'")) + "'" + "," + "'" + (mem_role.replaceAll("'", "'")) + "'" + "," + "'" + (middleName.replaceAll("'", "'")) + "'" + "," + "'" + (phone.replaceAll("'", "'")) + "'" + "," + "'" + (has_comp.replaceAll("'", "'")) + "'" + ")"; // System.out.println(sql); stm.executeUpdate(sql); } else { String sql = "update " + TABLE_NAME + " set " + "first_name ='" + (firstName.replaceAll("'", "'")) + "'" + "," + "last_name ='" + (lastName.replaceAll("'", "'")) + "'" + "," + "addr1 ='" + (addr1.replaceAll("'", "'")) + "'" + "," + "addr2 ='" + (addr2.replaceAll("'", "'")) + "'" + "," + "email ='" + (email.replaceAll("'", "'")) + "'" + "," + "birth ='" + (birth.replaceAll("'", "'")) + "'" + "," + "cell ='" + (cell.replaceAll("'", "'")) + "'" + "," + "fam_role ='" + (fam_role.replaceAll("'", "'")) + "'" + "," + "fam_pid ='" + (familypid.replaceAll("'", "'")) + "'" + "," + "mem_role ='" + (mem_role.replaceAll("'", "'")) + "'" + "," + "middle_name ='" + (middleName.replaceAll("'", "'")) + "'" + "," + "phone ='" + (phone.replaceAll("'", "'")) + "'" + "," + "has_comp ='" + (has_comp.replaceAll("'", "'")) + "'" + " " + "where pid='" + pid + "'"; // System.out.println(sql); stm.executeUpdate(sql); } conn.close(); stm.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }