怎样写个方法来检验用户名不存在!加个鸡毛!在线等!
肯定要连数据库里面的表,这个方法怎么写啊!
username password 
00001     ******
00002     ******
连数据库就不要说拉就是这个检验用户名的方法啊995!

解决方案 »

  1.   

    select count(id) form table where username='jordan';返回0,没有
    返回大于0的数字,有
      

  2.   

    public boolean execute(HttpServletRequest req) throws Exception {
    boolean flag = false;
    if(getrequest(req)){
    String sqlStr = "select UserName from [admin] where UserName='00001'";
    //msg = sqlStr;
    BookBase db = new BookBase();
    conn = db.getConnection();
    stmt = conn.createStatement();
    try {
    rs = stmt.executeQuery(sqlStr);
    if(rs.next()){
    flag = false;
    }else{
    flag= true;
    }
    } catch (SQLException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }finally{
    if(null!=rs) rs.close();
    if(null!=stmt) stmt.close();
    db.closeConnection(conn);
    }
    }
    return flag;
    }