public List<Account> findByCondition( String idcardNo, String realName, String loginName, String status, int page, int pageSize) throws DAOException { // 用来封住查询条件的值 List<Object> params = new ArrayList<Object>(); StringBuffer sb = buildFIndSQL(idcardNo, realName, loginName, status, page, pageSize, params); List<Account> accs = new ArrayList<Account>(); Connection conn = DBUtil.getConnection(); try { PreparedStatement pstmt = conn.prepareStatement(sb.toString()); for (int i = 0; i < params.size(); i++) { pstmt.setObject(i + 1, params.get(i)); } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { Account a = createAccount(rs); accs.add(a); } } catch (Exception e) { e.printStackTrace(); throw new DAOException("查询账务账户失败", e); } finally { DBUtil.closeConnection(); } return accs; }
public Account findById(int id) throws DAOException { String sql = "select * from account where id=?"; Connection conn = DBUtil.getConnection(); try { PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { return createAccount(rs); } } catch (Exception e) { e.printStackTrace(); throw new DAOException("根据id查询账务账号信息失败!", e); } finally { DBUtil.closeConnection(); } return null; }
public void pauseAccount(int id) throws DAOException { String sql = "update account set status='1',pause_date=sysdate where id=?"; Connection conn = DBUtil.getConnection(); try { conn.setAutoCommit(false); PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); pstmt.executeUpdate(); conn.commit(); } catch (SQLException e) { e.printStackTrace(); try { conn.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } throw new DAOException("暂停账务账号失败!", e); } finally { DBUtil.closeConnection(); } }
public Account findByIdcardNo(String idcardNo) throws DAOException { if (idcardNo == null) { return null; } String sql = "select * from account where idcard_no=?"; Connection conn = DBUtil.getConnection(); PreparedStatement pstmt; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, idcardNo); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { return createAccount(rs); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { DBUtil.closeConnection(); } return null; }