<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
    數據加載中……

    2012年5月26日

    一個簡單的關于權限判斷登陸的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 @ 2012-05-26 20:06 L遷客 閱讀(1641) | 評論 (1)編輯 收藏

    主站蜘蛛池模板: 亚洲国产精品无码成人片久久| 最好免费观看韩国+日本| 精品国产人成亚洲区| 国产精品久久亚洲一区二区| 老司机永久免费网站在线观看| 久久精品国产亚洲AV蜜臀色欲 | 1000部拍拍拍18免费网站| 亚洲va在线va天堂va四虎| 久久免费看少妇高潮V片特黄| 亚洲国产一区国产亚洲| 91青青国产在线观看免费| 亚洲成人高清在线观看| 成人AV免费网址在线观看| 亚洲熟妇成人精品一区| 国产美女无遮挡免费网站| 无码毛片一区二区三区视频免费播放 | 国产成人免费永久播放视频平台| 久久精品国产亚洲av天美18| 国产在线播放免费| 一区二区三区免费看| 亚洲av无码一区二区三区网站| 最近免费中文在线视频| 国产亚洲精品bv在线观看 | 亚洲精品线路一在线观看| 成人免费777777被爆出| 亚洲黄色片在线观看| 成人免费无码大片a毛片 | 国产免费AV片在线观看| 亚洲欧洲日本精品| 日韩特黄特色大片免费视频| 一边摸一边爽一边叫床免费视频| 亚洲国产精品不卡在线电影| 青苹果乐园免费高清在线| 极品美女一级毛片免费| 水蜜桃亚洲一二三四在线| 久久久久久国产a免费观看黄色大片| 大桥未久亚洲无av码在线| 亚洲色欲久久久综合网东京热| 国产精品视频免费观看| 含羞草国产亚洲精品岁国产精品| 亚洲热妇无码AV在线播放|