@Override public List<CertType> findMH(String s, Object o) { // TODO Auto-generated method stub Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; List<CertType> certTypeList = new ArrayList<CertType>(); String sql = "select * from tab_certtype where " + s + " like '%" + o + "%'"; try { conn = DBUtils.getconnection(); pstmt = conn.prepareStatement(sql); // pstmt.setObject(1, "'%" + o + "%'"); rs = pstmt.executeQuery(); while (rs.next()) { CertType ct = new CertType(); ct.setID(rs.getInt("ID")); ct.setContent(rs.getString("content")); certTypeList.add(ct); } } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("findMH error!"); } finally { // DBUtils.closeConnection(conn); DBUtils.closeStatement(rs, pstmt); } return certTypeList; }
// ���ң���ȷ���� + ģ����� @Override public CertType findJQ(String s, Object o) { CertType ct = null; PreparedStatement pstmt = null; ResultSet rs = null; String sql = "select * from tab_certtype where " + s + "=?"; try { pstmt = conn.prepareStatement(sql); pstmt.setObject(1, o); rs = pstmt.executeQuery(); if (rs.next()) { ct = new CertType(); ct.setID(rs.getInt("ID")); ct.setContent(rs.getString("content")); } } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("findJQ error!"); } finally { DBUtils.closeStatement(rs, pstmt); // DBUtils.closeConnection(conn); } return ct; }
public User findUser(User u) { User user = null; Connection conn = null; try { conn = DBUtils.getconnection(); UserDaoImpl udi = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); user = udi.findUser(u); DBUtils.commit(conn); } catch (Exception e) { DBUtils.rollBack(conn); System.out.println("findUser in UserServince error!"); } finally { DBUtils.closeConnection(conn); } return user; }
public int updateUser(User one) throws Exception { Connection conn = null; int res = 0; try { conn = DBUtils.getconnection(); UserDaoImpl userDaoImpl = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); res = userDaoImpl.updateUser(one); DBUtils.commit(conn); } catch (SQLException e) { DBUtils.rollBack(conn); System.out.println("updateUser error!"); } finally { DBUtils.closeConnection(conn); } return res; }
/** * 获取指定页用户信息列表,通过分页SQL语句实现 * * @param pageSize ,每页显示信息条数 * @param rowNum ,需要获取的页数 * @param one ,需要获取的页数 * @return 用户信息列表,List[User],若无满足条件则列表为空 * @throws SQLException */ public List<User> getUserList(int pageSize, int rowNum, User one) { Connection conn = null; List<User> res = null; try { conn = DBUtils.getconnection(); UserDao userDao = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); res = userDao.getUserList(pageSize, rowNum, one); DBUtils.commit(conn); } catch (Exception e) { DBUtils.rollBack(conn); System.out.println("getUserList error!"); } finally { DBUtils.closeConnection(conn); } return res; }
public User login(String username, String password) { User u = null; Connection conn = null; int i = 0; try { conn = DBUtils.getconnection(); UserDaoImpl udi = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); u = udi.login(username, password); DBUtils.commit(conn); } catch (Exception e) { DBUtils.rollBack(conn); System.out.println("save error!"); } finally { DBUtils.closeConnection(conn); } return u; }
public boolean deleteUsers(int[] userIdList) throws Exception { boolean s = false; Connection conn = null; int i = 0; try { conn = DBUtils.getconnection(); UserDaoImpl udi = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); s = udi.deleteUsers(userIdList); DBUtils.commit(conn); } catch (Exception e) { DBUtils.rollBack(conn); System.out.println("deleteUsers error!"); } finally { DBUtils.closeConnection(conn); } return s; }
public boolean save(User u) { boolean s = false; Connection conn = null; int i = 0; try { conn = DBUtils.getconnection(); UserDaoImpl udi = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); s = udi.save(u); DBUtils.commit(conn); } catch (Exception e) { DBUtils.rollBack(conn); System.out.println("save error!"); } finally { DBUtils.closeConnection(conn); } return s; }
/** * 获取用户列表最大页数 * * @param pageSize ,每页显示信息条数 * @return 列表最大页数 * @throws Exception * @throws SQLException */ public int getUserListPageCount(int pageSize, User one) throws Exception { Connection conn = null; int res = 0; try { conn = DBUtils.getconnection(); UserDaoImpl userDao = new UserDaoImpl(conn); DBUtils.beginTransaction(conn); res = userDao.getUserListPageCount(pageSize, one); DBUtils.commit(conn); } catch (SQLException e) { DBUtils.rollBack(conn); System.out.println("getUserListPageCount error!"); } finally { DBUtils.closeConnection(conn); } return res; }
/** * 根据省份标识获取所有城市信息列表 * * @param proID * @return * @throws SQLException */ public List<City> getCityListByProID(String proID) { Connection conn = null; List<City> res = null; try { conn = DBUtils.getConnection(); CityDao cityDao = new CityDaoImpl(conn); DBUtils.beginTransaction(conn); res = cityDao.getCityListByProID(proID); DBUtils.commit(conn); } catch (SQLException e) { DBUtils.rollback(conn); throw new ServiceException("查询错误", e); } finally { DBUtils.closeConnection(conn); } return res; }
public List<CertType> getCertType() throws SQLException { PreparedStatement pstmt = null; ResultSet rs = null; List<CertType> certTypeList = new ArrayList<CertType>(); try { pstmt = conn.prepareStatement("select * from tab_certtype"); rs = pstmt.executeQuery(); while (rs.next()) { CertType ct = new CertType(); ct.setID(rs.getInt("ID")); ct.setContent(rs.getString("content")); certTypeList.add(ct); } } finally { // rs.close(); // pstmt.close(); // DBUtils.closeConnection(conn); DBUtils.closeStatement(rs, pstmt); } return certTypeList; }