我认为的权限是这么做的
第一步:分成三个等级(管理员、教师、学生)
还没想出三个等级分别对应哪些功能,我们一步一步来!奥利给!
int judgeNum;
MyDBConnection mydbcon;
Connection conn ;
Statement stam ;
private int judge() {
String sql = "select * from tb_logging";
try {
ResultSet re = stam.executeQuery(sql);
while(re.next()) {
String userNum = re.getString("account").trim();
String userPwd=re.getString("code").trim();
int right = re.getInt("_power");
if(userNum.equals(identNum.getText())&&userPwd.equals(new String(identPassword.getPassword()))&&right == 1) {
judgeNum=1;break;
}else if(userNum.equals(identNum.getText())&&userPwd.equals(new String(identPassword.getPassword()))&&right == 2) {
judgeNum=2;break;
}else if(userNum.equals(identNum.getText())&&userPwd.equals(new String(identPassword.getPassword()))&&right == 3) {
judgeNum=3;break;
}else {
judgeNum=4;
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
return judgeNum;
}
划分好之后我们马上开始实现它!跳到它对应的页面中去!
implements ActionListener(记得要先实现这个方法哦)
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == login) {
if(judge() == 1) {
System.out.println("管理员已登录!");
//预留管理员窗口跳转接口
}else if(judge()== 2) {
System.out.println("教师已登录!");
//预留教师窗口跳转接口
}else if(judge() == 3) {
System.out.println("学生已登录!");
//预留学生窗口跳转接口
}else {
JOptionPane.showMessageDialog(null, "账户或密码错误","提示",2);
}
}
}
到这里权限划分完成!
public LoginFrame(MyDBConnection mydbcon) {
this.mydbcon = mydbcon;
this.conn = mydbcon.getMyConnection();
this.stam = mydbcon.getMyStatement();
login.addActionListener(this);
}
String DBDriver="com.mysql.jdbc.Driver";
String DBURL="jdbc:mysql://localhost:3306/choosecourse";
String DBUser="root";
String DBPass="111";
MyDBConnection myDB=new MyDBConnection(DBDriver,DBURL,DBUser,DBPass);
LoginFrame logf = new LoginFrame(myDB);
MyDBConnection方法,上一篇讲到过怎么实现,请看上一篇讲解!
调用连接测试!over!