📄 login.java
字号:
package hall;
/**
* Project: NWPU online shop
* JDK version used: jdk1.5.0
* Version: 1.01
* class login 用来处理关于用户的登陆问题
*/
import java.sql.*;
public class login{
private String username; //登录用户名
private String passwd; //登录密码
private DBWrapper myConnection = null;//数据库连接和操作
private String sqlStr;
public login() throws Exception{
username = "";
passwd = "";
myConnection = DBWrapper.Instance();
sqlStr = "";
}
public String getUsername() {
return username;
}
public void setUsername(String newusername) {
username = newusername;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String newpasswd) {
passwd = newpasswd;
}
/**
* int excute()
* 执行查询,1代表此用户名是管理员在使用的,2代表此用户名是顾客在使用的,3代表此用户名没有被使用
* @return int
* @throws java.lang.Exception
*/
public int excute() throws Exception {
int flag = 3;//1 represents admin,2 represents customer,3 represents that the use isn't exsited
sqlStr = "select * from administrators where username = '" +
username + "' and password = '" +
passwd + "'";
ResultSet rs = myConnection.runQuery(sqlStr);
if (rs.next()){
flag = 1;
}
else{
sqlStr = "select * from customers where name = '" +
username + "' and password = '" +
passwd + "'";
rs = myConnection.runQuery(sqlStr);
if(rs.next()){
flag = 2;
}
else{
flag = 3;
}
}
rs.close();
return flag;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -