<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    L遷客

    技術(shù)博客
    隨筆 - 1, 文章 - 12, 評(píng)論 - 1, 引用 - 0
    數(shù)據(jù)加載中……

    一個(gè)簡(jiǎn)單的關(guān)于權(quán)限判斷登陸的javaBean文件

    package userce;

    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class UserCheck {
      Connection con;
      ResultSet rs;
      public UserCheck() { }
      public Connection getConnect(){ //連接數(shù)據(jù)庫(kù)的,不用在多說(shuō)了吧
       try{
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            }
       catch(ClassNotFoundException e){}
            String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=flDataSource";
            String name = "sa";//建議設(shè)計(jì)數(shù)據(jù)庫(kù)時(shí),不要用默認(rèn)的sa,可以建立一個(gè)有操作權(quán)限的用戶(hù);
            String pass = "sa";
        try{
            con = DriverManager.getConnection(url,name,pass);
            }
        catch(SQLException e){}
            return con;
      }
     public  boolean userExist(String username){
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        boolean occupied=true;
        try{
           String sqlquery="select *from Userlist where username=?";
           con=this.getConnect();
           //this.getConnect()=getConnect();//關(guān)于this 的用法,我到現(xiàn)在理解的也不是太透徹,我這樣用,在實(shí)際操作中是通過(guò)的,如果有不妥之處,請(qǐng)高手指教.
           ps=con.prepareStatement(sqlquery);
           ps.setString(2,username);
           rs=ps.executeQuery();
           if(!rs.next())
             occupied=false;
        }
        catch(SQLException e){
           e.printStackTrace();
        }
        finally{
          if(rs!=null) try{rs.close();}
                       catch(SQLException ignore){}
          if(ps!=null) try{ps.close();}
                       catch(SQLException ignore){}
          if(con!=null) try{con.close();}
                       catch(SQLException ignore){}
        }
        return occupied;
     }
    public boolean isValidUser(String username,String userpwd){//此函數(shù)用來(lái)判斷是否有此用戶(hù),其實(shí)很好理解我定義成boolean型,就可以根據(jù)返回值來(lái)進(jìn)行一個(gè)<jsp:forword="mmm.jsp">.
       Connection con=null;
       PreparedStatement ps=null;
       ResultSet rs=null;
       boolean isValid=false;
       try{
          String sqlquery="select *from Userlist where username=? and userpwd=?";
          con=this.getConnect();
          ps=con.prepareStatement(sqlquery);
          ps.setString(1,username);
          ps.setString(2,userpwd);
          rs=ps.executeQuery();
          if(rs.next())
            isValid=true;
       }
       catch(SQLException e){
          e.printStackTrace();
       }
       finally{
             if(rs!=null) try{rs.close();}
                          catch(SQLException ignore){}
             if(ps!=null) try{ps.close();}
                          catch(SQLException ignore){}
             if(con!=null) try{con.close();}
                          catch(SQLException ignore){}
       }
       return isValid;
     }
      public int getUserPri(String username){  //次方法我用來(lái)根據(jù)傳入的參數(shù):username(我設(shè)置session時(shí),用的也是username,根據(jù)檢索數(shù)據(jù)庫(kù)中的0,1標(biāo)志位,來(lái)判斷用戶(hù)的權(quán)限,這樣就可以進(jìn)行相應(yīng)的操作.)
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        int pri=0;
        try{
          String sqlquery="select variety from Userlist where username=? ";
          con=this.getConnect();
          ps=con.prepareStatement(sqlquery);
          ps.setString(1,username);
          rs=ps.executeQuery();
          if(rs.next())
            pri=rs.getInt("variety");
        }
        catch(SQLException e){
            e.printStackTrace();
        }
        finally{
           if(rs!=null) try{rs.close();}
                        catch(SQLException ignore){}
           if(ps!=null) try{ps.close();}
                        catch(SQLException ignore){}
           if(con!=null) try{con.close();}
                        catch(SQLException ignore){}

        }
        return pri;
      }
    }

    posted on 2012-05-26 20:06 L遷客 閱讀(1641) 評(píng)論(1)  編輯  收藏

    評(píng)論

    # re: 一個(gè)簡(jiǎn)單的關(guān)于權(quán)限判斷登陸的javaBean文件  回復(fù)  更多評(píng)論   

    其實(shí)應(yīng)該在檢查用戶(hù)是否存在的時(shí)候返回一個(gè)integer -1不存在,0密碼錯(cuò)誤 1 通過(guò)。
    檢查的時(shí)候用用戶(hù)名查詢(xún) 查詢(xún)到0條表示不存在,1條表示存在,1+條表示系統(tǒng)錯(cuò)誤。 1的時(shí)候再equals一下passWord
    2012-05-27 20:33 | 葉知泉

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久亚洲国产成人精品性色 | 3d成人免费动漫在线观看| 亚洲精品无码专区2| 污视频网站在线免费看| 免费人妻av无码专区| 免费一级毛片在线播放放视频| 四虎1515hm免费国产| 一级毛片免费在线播放| 亚洲欭美日韩颜射在线二| 久久午夜免费鲁丝片| 久久久久久亚洲AV无码专区| 免费在线视频你懂的| 亚洲中文字幕无码中文| 国产一区二区三区免费在线观看| 免费一级特黄特色大片| 亚洲一区精品无码| 99re免费在线视频| 亚洲av产在线精品亚洲第一站| 女人张腿给男人桶视频免费版| 国产亚洲欧美日韩亚洲中文色| mm1313亚洲精品国产| 嫩草在线视频www免费看| 久久久无码精品亚洲日韩京东传媒| 人成午夜免费视频在线观看| 亚洲成在人线aⅴ免费毛片| 久久久久亚洲AV成人网人人软件| 暖暖日本免费中文字幕| 亚洲一卡2卡3卡4卡乱码 在线| 国产三级电影免费观看| 免费91麻豆精品国产自产在线观看 | 9277手机在线视频观看免费| 亚洲一区二区三区久久| 国产18禁黄网站免费观看| 伊人免费在线观看| 色婷五月综激情亚洲综合| 国产偷窥女洗浴在线观看亚洲| 99久在线国内在线播放免费观看| 亚洲大码熟女在线观看| 亚洲成亚洲乱码一二三四区软件| 亚洲欧洲免费无码| AAAAA级少妇高潮大片免费看|