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

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

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

    L遷客

    技術博客
    隨筆 - 1, 文章 - 12, 評論 - 1, 引用 - 0
    數據加載中……

    一個簡單的關于權限判斷登陸的javaBean文件

    package userce;

    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class UserCheck {
      Connection con;
      ResultSet rs;
      public UserCheck() { }
      public Connection getConnect(){ //連接數據庫的,不用在多說了吧
       try{
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            }
       catch(ClassNotFoundException e){}
            String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=flDataSource";
            String name = "sa";//建議設計數據庫時,不要用默認的sa,可以建立一個有操作權限的用戶;
            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();//關于this 的用法,我到現在理解的也不是太透徹,我這樣用,在實際操作中是通過的,如果有不妥之處,請高手指教.
           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){//此函數用來判斷是否有此用戶,其實很好理解我定義成boolean型,就可以根據返回值來進行一個<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){  //次方法我用來根據傳入的參數:username(我設置session時,用的也是username,根據檢索數據庫中的0,1標志位,來判斷用戶的權限,這樣就可以進行相應的操作.)
        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) 評論(1)  編輯  收藏

    評論

    # re: 一個簡單的關于權限判斷登陸的javaBean文件  回復  更多評論   

    其實應該在檢查用戶是否存在的時候返回一個integer -1不存在,0密碼錯誤 1 通過。
    檢查的時候用用戶名查詢 查詢到0條表示不存在,1條表示存在,1+條表示系統錯誤。 1的時候再equals一下passWord
    2012-05-27 20:33 | 葉知泉

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 三上悠亚电影全集免费| 另类图片亚洲校园小说区| 免费网站观看WWW在线观看| 国产一级做a爱免费视频| 亚洲av中文无码乱人伦在线观看 | eeuss影院www天堂免费| 免费又黄又硬又爽大片| 99精品在线免费观看| 亚洲精品成人片在线播放| 精品乱子伦一区二区三区高清免费播放| 亚洲Av无码国产情品久久| 亚洲AV无码一区二区三区性色| 午夜毛片不卡免费观看视频| 久久亚洲AV无码西西人体| 日韩一级片免费观看| 亚洲午夜av影院| 最近免费中文字幕中文高清 | 中文字幕无码一区二区免费| 亚洲Av综合色区无码专区桃色| 精品无码国产污污污免费网站| 337p日本欧洲亚洲大胆色噜噜| 在线观看成人免费视频不卡| 亚洲色精品三区二区一区| 一区二区三区亚洲视频| a级毛片毛片免费观看永久| 亚洲视频在线不卡| 最近免费中文字幕视频高清在线看| 亚洲第一成年网站视频| 亚洲Av无码乱码在线播放| 午夜视频在线免费观看| 亚洲国产精品一区二区久| 日韩免费视频播播| 免费国产叼嘿视频大全网站| 亚洲一区二区三区在线观看蜜桃 | 中文字幕免费不卡二区| 亚洲人成在线播放| 久久久久无码专区亚洲av| 日韩精品在线免费观看| 亚洲中文字幕AV每天更新| 亚洲综合无码精品一区二区三区| **实干一级毛片aa免费|