锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
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";//寤鴻璁捐鏁版嵁搴撴椂錛屼笉瑕佺敤榛樿鐨剆a,鍙互寤虹珛涓涓湁鎿嶄綔鏉冮檺鐨勭敤鎴鳳紱
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鍨嬶紝灝卞彲浠ユ牴鎹繑鍥炲兼潵榪涜涓涓?lt;jsp:forword錛濓紓mmm.jsp錛?gt;.
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錛?鏍囧織浣嶏紝鏉ュ垽鏂敤鎴風殑鏉冮檺錛岃繖鏍峰氨鍙互榪涜鐩稿簲鐨勬搷浣滐紟錛?br /> 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;
}
}