Ejemplo n.º 1
0
 public void creat(Reader rd) {
   Connection cn = null;
   PreparedStatement ps = null;
   try {
     cn = JDBCTools.getConnection();
     String spl =
         "insert into reader(r_id,r_password,r_name,r_age,r_typed,r_sex,r_dept,r_phone,r_address,r_photo)values(?,?,?,?,?,?,?,?,?,?)";
     ps = cn.prepareStatement(spl);
     ps.setString(1, rd.getReaderid());
     ps.setString(2, rd.getPassword());
     ps.setString(3, rd.getName());
     ps.setInt(4, rd.getAge());
     ps.setInt(5, rd.getTyped());
     ps.setString(6, rd.getSex());
     ps.setString(7, rd.getDept());
     ps.setString(8, rd.getPhone());
     ps.setString(9, rd.getAddress());
     ps.setString(10, rd.getPhoto());
     ps.executeUpdate();
   } catch (SQLException e) {
     throw new DaoException();
   } finally {
     JDBCTools.free(ps, cn);
   }
 }
Ejemplo n.º 2
0
  public void delete(Reader rd) {
    Connection cn = null;
    PreparedStatement ps = null;
    try {
      cn = JDBCTools.getConnection();
      String spl = "delete from reader where r_id=?";
      ps = cn.prepareStatement(spl);
      ps.setString(1, rd.getReaderid());
      ps.executeUpdate();
    } catch (SQLException e) {
      throw new DaoException();
    } finally {

      JDBCTools.free(ps, cn);
    }
  }
Ejemplo n.º 3
0
  public boolean readLogin(Reader rd) {
    Connection cn = null;
    Statement ps = null;
    ResultSet rs = null;
    try {
      cn = JDBCTools.getConnection();
      ps = cn.createStatement();
      rs = ps.executeQuery("select *from reader");
      while (rs.next()) {
        boolean w =
            rd.getReaderid().equals(rs.getString(1)) && rd.getPassword().equals(rs.getString(2));
        if (w) {
          return true;
        }
      }

    } catch (SQLException e) {
      throw new DaoException();
    } finally {
      try {
        if (cn != null) cn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } finally {
        try {
          if (ps != null) ps.close();
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } finally {
          try {
            if (rs != null) rs.close();
          } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }

    return false;
  }