/** * 说明:更新给定的部门对象 * * @param con 数据库连接对象 * @param source 部门对象 * @throws LawyerException */ public void updateDepartment(Connection con, Department source) throws LawyerException { String sql = "UPDATE " + DEPTABLE + " SET NAME=?,STATUS=?,SDATE=?,EDATE=?,REMARKS=?,PRINCIPAl=? WHERE ID='" + source.getId() + "' AND SYSID='" + source.getSysID() + "'"; PreparedStatement psment = null; try { psment = con.prepareStatement(sql); // 清除参数 psment.clearBatch(); psment.setString(1, source.getName()); psment.setString(2, source.getStatus()); psment.setDate( 3, null == source.getSdate() ? new java.sql.Date(new Date().getTime()) : new java.sql.Date(source.getSdate().getTime())); psment.setDate( 4, null == source.getEdate() ? new java.sql.Date(new Date().getTime()) : new java.sql.Date(source.getEdate().getTime())); psment.setString(5, source.getRemarks()); psment.setString(6, source.getPrincipal()); psment.addBatch(); // 执行数据库插入处理 psment.execute(); } catch (SQLException e) { throw new LawyerException("Update Department is error! " + e.getMessage()); } finally { try { psment.close(); } catch (SQLException e) { } psment = null; } }
/** * 说明:存储给定的部门对象 * * @param con 数据库连接对象 * @param source 部门对象 * @throws LawyerException */ public void saveDepartment(Connection con, Department source) throws LawyerException { String sql = "INSERT INTO " + DEPTABLE + "(ID,NAME,STATUS,SDATE,EDATE,REMARKS,PRINCIPAl,SYSID) VALUES(?,?,?,?,?,?,?,?)"; PreparedStatement psment = null; try { psment = con.prepareStatement(sql); // 清除参数 psment.clearBatch(); psment.setString(1, source.getId()); psment.setString(2, source.getName()); psment.setString(3, source.getStatus()); psment.setDate( 4, null == source.getSdate() ? new java.sql.Date(new Date().getTime()) : new java.sql.Date(source.getSdate().getTime())); psment.setDate( 5, null == source.getEdate() ? new java.sql.Date(new Date().getTime()) : new java.sql.Date(source.getEdate().getTime())); psment.setString(6, source.getRemarks()); psment.setString(7, source.getPrincipal()); psment.setString(8, source.getSysID()); psment.addBatch(); // 执行数据库插入处理 psment.execute(); } catch (SQLException e) { throw new LawyerException("Save Department is error! " + e.getMessage()); } finally { try { psment.close(); } catch (SQLException e) { } psment = null; } }
/** * 说明:获取指定系统指定部门标识的部门对象 * * @param con 数据库连接对象 * @param sysid 系统标识 * @param depid 部门标识 * @return * @throws LawyerException */ public Department queryDepartment(Connection con, String sysid, String depid) throws LawyerException { String sql = "SELECT ID,NAME,STATUS,SDATE,EDATE,REMARKS,PRINCIPAl,SYSID FROM " + DEPTABLE + " WHERE SYSID='" + sysid + "' AND ID='" + depid + "'"; Statement statment = null; ResultSet result = null; try { statment = con.createStatement(); result = statment.executeQuery(sql); Department department = null; while (result.next()) { department = new Department(result.getString("SYSID"), result.getString("ID")); department.setName(result.getString("NAME")); department.setStatus(result.getString("STATUS")); department.setSdate(result.getDate("SDATE")); department.setEdate(result.getDate("EDATE")); department.setPrincipal(result.getString("PRINCIPAl")); department.setRemarks(result.getString("REMARKS")); break; } return department; } catch (SQLException e) { throw new LawyerException("Query Department is error! " + e.getMessage()); } finally { try { result.close(); statment.close(); } catch (SQLException e) { } result = null; statment = null; } }
/** * 说明:删除给定的部门对象 * * @param con 数据库连接对象 * @param source 部门对象 * @throws LawyerException */ public void deleteDepartment(Connection con, Department source) throws LawyerException { deleteDepartment(con, source.getSysID(), source.getId()); }