// 增加病人信息 public boolean addPatient(Patient p) { boolean flag = false; Connection conn = null; PreparedStatement pst = null; try { conn = DBHelp.getConnection(); String sql = "insert into patient(room,name,sex,entertime,doctor,section,cation,bed) values (?,?,?,getdate(),?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, p.getRoom()); pst.setString(2, p.getName()); pst.setString(3, p.getSex()); pst.setString(4, p.getDoctor()); pst.setString(5, p.getSection()); pst.setString(6, p.getCation()); pst.setInt(7, p.getBed()); if (pst.executeUpdate() > 0) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBHelp.closeConn(pst); DBHelp.closeConn(conn); } return flag; }
// 更新病人信息 public boolean uptPatient(Patient p, int id) { boolean flag = false; Connection conn = null; PreparedStatement pst = null; try { conn = DBHelp.getConnection(); String sql = "update patient set name=?,sex=?,doctor=?,section=?,room=?,bed=?,cation=? where id=" + id; pst = conn.prepareStatement(sql); pst.setString(1, p.getName()); pst.setString(2, p.getSex()); pst.setString(3, p.getDoctor()); pst.setString(4, p.getSection()); pst.setString(5, p.getRoom()); pst.setInt(6, p.getBed()); pst.setString(7, p.getCation()); if (pst.executeUpdate() > 0) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBHelp.closeConn(pst); DBHelp.closeConn(conn); } return flag; }