public ResultSet departmentList(Connection con, pageBean pageBean, departmentList department) throws Exception { StringBuffer sb = new StringBuffer("select * from table_department"); if (department != null && StringUtil.isNotEmpty(department.getDepartmentInfo())) { sb.append(" and departmentInfo like '%" + department.getDepartmentInfo() + "%'"); } if (pageBean != null) { sb.append(" limit " + pageBean.getStart() + "," + pageBean.getRows()); } PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where")); return pstmt.executeQuery(); }
public int departmentCount(Connection con, departmentList department) throws Exception { StringBuffer sb = new StringBuffer("select count(*) as total from table_department"); if (StringUtil.isNotEmpty(department.getDepartmentInfo())) { sb.append(" and departmentInfo like '%" + department.getDepartmentInfo() + "%'"); } PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where")); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { return rs.getInt("total"); } else { return 0; } }