Exemplo n.º 1
0
  // ɾ³ý
  @Override
  public int delete(String uid) {
    String sql = "delete from adduser where u_id =" + uid;
    Connection conn = null;
    PreparedStatement ps = null;
    int i = 0;
    try {
      try {
        conn = JDBCConnection.getConnection();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      ps = conn.prepareStatement(sql);
      i = ps.executeUpdate();
      System.out.println("resutl" + i);
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JDBCConnection.close(ps);
      JDBCConnection.close(conn);
    }

    return i;
  }
Exemplo n.º 2
0
 // ²åÈë
 @Override
 public int insert(User user) {
   Connection conn = null;
   PreparedStatement ps = null;
   int i = 0;
   String sql =
       "insert into adduser (uid,userame,usex,phone,subjects,email,password)values(?,?,?,?,?,?,?)";
   try {
     try {
       conn = JDBCConnection.getConnection();
     } catch (ClassNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     ps = conn.prepareStatement(sql);
     ps.setLong(1, user.getUid());
     ps.setString(2, user.getUsername());
     ps.setString(3, user.getUsex());
     ps.setString(4, user.getPhone());
     ps.setObject(5, user.getSubjects());
     ps.setString(6, user.getEmail());
     ps.setString(7, user.getPassword());
     i = ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     JDBCConnection.close(ps);
     JDBCConnection.close(conn);
   }
   return i;
 }
Exemplo n.º 3
0
  // ÐÞ¸Ä
  @Override
  public int update(User user) {
    Connection conn = null;
    PreparedStatement ps = null;
    int i = 0;
    String sql =
        "update adduser (uid,password,userame,usex,phone,subjects,email) set u_name= ?where u_id = ?";
    try {
      try {
        conn = JDBCConnection.getConnection();
      } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      ps = conn.prepareStatement(sql);
      i = ps.executeUpdate();
      System.out.println("resutl:" + i);
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JDBCConnection.close(ps);
      JDBCConnection.close(conn);
    }

    return i;
  }
Exemplo n.º 4
0
 @Override
 public List<Map<String, Object>> list() {
   JDBCConnection db = new JDBCConnection();
   String sql = "select * from subject";
   List<Map<String, Object>> list = db.query1(sql);
   System.out.print(list + "&&&&&&&&");
   return list;
 }
Exemplo n.º 5
0
  // 修改科目
  public Subject updateSubject(String sname) {

    String sql = "update subject set name ='" + sname + "'";
    try {
      conn = JDBCConnection.getConnection();
      ps = conn.prepareStatement(sql);
      ps.executeUpdate();

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JDBCConnection.close(rs);
      JDBCConnection.close(ps);
      JDBCConnection.close(conn);
    }
    return null;
  }
Exemplo n.º 6
0
  // 添加科目
  @Override
  public Subject addSubject(String sname) {
    String sql = "insert into subject(name) values('" + sname + "')";
    try {
      conn = JDBCConnection.getConnection();
      ps = conn.prepareStatement(sql);
      ps.executeUpdate();

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JDBCConnection.close(rs);
      JDBCConnection.close(ps);
      JDBCConnection.close(conn);
    }
    return null;
  }
Exemplo n.º 7
0
  // ²éѯ
  @Override
  public User query(String username) {
    String sql = "SELECT * FROM adduser WHERE username = ?";
    User user = null;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {

      conn = JDBCConnection.getConnection();

      ps = conn.prepareStatement(sql);
      ps.setString(1, username);
      rs = ps.executeQuery();
      if (rs.next()) {
        user = new User();
        user.setUid(rs.getLong("uid"));
        user.setUsex(rs.getString("usex"));
        user.setUsername(rs.getString("username"));
        user.setPassword(rs.getString("password"));
        user.setPhone(rs.getString("phone"));
        user.setEmail(rs.getString("email"));
        user.setSubjects(rs.getString("subjects"), null); //
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } finally {
      JDBCConnection.close(rs);
      JDBCConnection.close(ps);
      JDBCConnection.close(conn);
    }

    return user;
  }