Пример #1
0
  /*
   * (non-Javadoc)
   *
   * @see org.test.dao.impl.IDirayDao#readList()
   */
  @Override
  public List<Diray> readList(Integer uid) {
    String sql = "select * from diray where uid=?";
    con = DB.getCon();
    List<Diray> list = new ArrayList<Diray>();
    try {
      pstmt = con.prepareStatement(sql);
      pstmt.setInt(1, uid);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        list.add(
            new Diray(
                rs.getInt(1),
                rs.getString(2),
                rs.getString(3),
                new Usr(rs.getInt(4)),
                rs.getString(5)));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DB.closeAll(con, pstmt, rs);
    }
    return list;
  }
Пример #2
0
 /*
  * (non-Javadoc)
  *
  * @see org.test.dao.impl.IDirayDao#delete(java.lang.Integer)
  */
 @Override
 public boolean delete(Integer id) {
   String sql = "delete from diray where id=?";
   try {
     pstmt = DB.getCon().prepareStatement(sql);
     pstmt.setInt(1, id);
     return pstmt.executeUpdate() > 0;
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DB.closeAll(con, pstmt, rs);
   }
   return false;
 }
Пример #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.test.dao.impl.IDirayDao#update(org.test.entity.Diray)
   */
  @Override
  public boolean update(Diray d) {
    String sql = "update diray set title=?, centent=?,publishtime=? where id=?";

    try {
      con = DB.getCon();
      pstmt = con.prepareStatement(sql);
      pstmt.setString(1, d.getTitle());
      pstmt.setString(2, d.getCentent());
      pstmt.setString(3, d.getPublishtime());
      pstmt.setInt(4, d.getId());
      return pstmt.execute();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DB.closeAll(con, pstmt, rs);
    }
    return false;
  }
Пример #4
0
  /*
   * (non-Javadoc)
   *
   * @see org.test.dao.impl.IDirayDao#read(java.lang.Integer)
   */
  @Override
  public Diray read(Integer id) {

    String sql = "select * from diray where id=? ";
    con = DB.getCon();
    ResultSet rs = null;
    try {
      pstmt = con.prepareStatement(sql);
      pstmt.setInt(1, id);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        return new Diray(rs.getInt(1), rs.getString(2), rs.getString(3));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DB.closeAll(con, pstmt, rs);
    }

    return null;
  }
Пример #5
0
  /*
   * (non-Javadoc)
   *
   * @see org.test.dao.impl.IDirayDao#create(org.test.entity.Diray)
   */
  @Override
  public boolean create(Diray d) {
    String sql = "insert into diray(title,centent,uid,publishtime) values(?,?,?,?)";
    con = DB.getCon();

    try {
      pstmt = con.prepareStatement(sql);
      pstmt.setString(1, d.getTitle());
      pstmt.setString(2, d.getCentent());
      pstmt.setInt(3, d.getUsr().getId());
      pstmt.setString(4, d.getPublishtime());
      if (pstmt.executeUpdate() > 0) {
        return true;
      }
    } catch (SQLException e) {

      e.printStackTrace();
    } finally {
      DB.closeAll(con, pstmt, rs);
    }
    return false;
  }