public boolean isAdmin(String adminId,String adminPwd)

package cn.edu.zjgsu.book.biz;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import cn.edu.zjgsu.book.bean.RegUser;


//�û�����
public class UserManager {
private Statement stmt;
private ResultSet rs;
private Connection con;
private String userId;
private String userName;
private String password;

//��ȡһ����ݿ�����
public UserManager()
{
con=DBManager.getConnection();
}
public Statement getStmt() {
return stmt;
}


public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

//����û���Ż�ȡ�û���Ϣ
public RegUser getUserByUserId(String userId)
{
RegUser regUser=null;
try {
stmt=con.createStatement();
String sql="select * from regUser where UserId='"+userId
+"'";
rs=stmt.executeQuery(sql);

//����ѯ���Ľ����ݴ���regUser��������
while(rs.next())
{
regUser=new RegUser();
regUser.setUserId(userId);
regUser.setPassword(rs.getString("Password"));
regUser.setUserName(rs.getString("UserName"));
regUser.setSex(rs.getString("Sex"));
regUser.setAddress(rs.getString("Address"));
regUser.setPhone(rs.getString("Phone"));
regUser.setPost(rs.getString("Post"));
regUser.setEmail(rs.getString("Email"));
regUser.setRegTime(rs.getDate("RegTime"));
regUser.setRegIpAddress(rs.getString("RegIpAddress"));

}
rs.close();
stmt.close();

} catch (SQLException e) {

e.printStackTrace();
}


return regUser;

}
//��֤�û��������
public RegUser isValidUser(String userId,String password)
{

RegUser regUser=this.getUserByUserId(userId);
if(regUser!=null)
{
if(!regUser.getPassword().equals(password))
regUser=null;
}
return regUser;

}


//�����û���Ϣ
public int updateUser(RegUser user)
{
int row=0;
try {
stmt=con.createStatement();
String sql="update reguser set Password='"+user.getPassword()+"',UserName='"
+user.getUserName()+"',Sex='"
+user.getSex()+"',Address='"
+user.getAddress()+"',Phone='"
+user.getPhone()+"',Post='"
+user.getPost()+"',Email='"
+user.getEmail()+"'where UserId='"
+user.getUserId()+"'";
row=stmt.executeUpdate(sql);
stmt.close();
} catch (SQLException e) {

e.printStackTrace();
}

return row;
}
//�ж��û��Ƿ��ǹ���Ա
public boolean isAdmin(String adminId,String adminPwd)
{
boolean validAdmin=false;
try {
stmt=con.createStatement();
String sql="select * from BookAdmin where adminId='"+adminId+"'";
rs=stmt.executeQuery(sql);
while(rs.next())
{
if(adminPwd.equals(rs.getString("AdminPwd").trim())){
validAdmin=true;

}
}
rs.close();
stmt.close();

} catch (SQLException e) {

e.printStackTrace();
}

return validAdmin;
}
//���û�ע��
public int signup(RegUser newUser){
int row=0;
if(this.getUserByUserId(newUser.getUserId())==null){
row=this.insertUser(newUser);

}
return row;
}
//����ݱ�RegUser�в����¼�¼
private int insertUser(RegUser user) {
int row=0;
try {
stmt=con.createStatement();
String sql="insert into reguser values('"+user.getUserId()+"','"+user.getPassword()+"','"
+user.getUserName()+"','"
+user.getSex()+"','"
+user.getAddress()+"','"
+user.getPhone()+"','"
+user.getPost()+"','"
+user.getEmail()+"','"
+user.getRegTime()+"','"+user.getRegIpAddress()+"')";
row=stmt.executeUpdate(sql);
stmt.close();
} catch (SQLException e) {

e.printStackTrace();
}

return row;
}

}

你可能感兴趣的:(java)