📄 userlogin.java
字号:
package bbs.beans.user;
import java.sql.*;
import java.util.Date;
import bbs.beans.dbcontact.ContactBean;
public class UserLogin
{ private Statement stm;
private String[] str=new String[3];
public UserLogin()
{ ContactBean contact=new ContactBean();
stm=contact.getStm();
}
public String[] getData()
{
return this.str;
}
/*login()方法中的userinfo对象保存登录成功的用户的信息,在jsp中用到UserLogin Bean时就将userinfo
中保存的信息再保存到session对象中*/
public int Login( String name,String pwd)throws Exception
{ int tag;
try
{
ResultSet result = stm.executeQuery("select * from userinfo where username='" +name + "'");
if(result.next()==true)
{ if(result.getString("userpwd").equalsIgnoreCase(pwd) )
{ if(result.getInt("idstop")==1)
{tag=3;}//3表示用户id被封
else
{
str[0] = result.getString("userid");
str[1] = name;
str[2] = pwd;
java.text.SimpleDateFormat format=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date Da = new Date();
String date = format.format(Da);
result=stm.executeQuery("select logins from userinfo where username='"+str[1]+"'");
result.next();
stm.executeUpdate("update userinfo set logins=" + (1+result.getInt(1)) +",online=1,lastlogdate='" + date +"' where username='" + str[1] + "'");
tag = 2; //2表示登录成功
// rst.close();
}
}
else
tag=1;//1表示用户密码不正确
}
else
tag=0;//0表示数据库中没有该用户
//result.close();
stm.close();
}
catch(Exception e)
{ e.printStackTrace() ;
throw e;
}
return tag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -