forked from kongxin-github/Java_Library_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanding.java
More file actions
70 lines (61 loc) · 1.61 KB
/
Landing.java
File metadata and controls
70 lines (61 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class Landing {
public static Boolean test(String user, String password) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from usertable where user = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, user);
rs = preSql.executeQuery();
boolean flag = false;
while(rs.next()) {
flag = true;
String password2 = rs.getString(4);
if (!(password.equals(password2))) {
JOptionPane.showMessageDialog(null, "密码错误", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
}
if(!flag) {
JOptionPane.showMessageDialog(null, "用户名不存在", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
con.close();
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "用户名不存在", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
}
//确定是否为管理员
public static boolean sureadmin(String user) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from usertable where user = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, user);
rs = preSql.executeQuery();
while(rs.next()) {
int admin = rs.getInt(5);
if (admin==1) {
return true;
}else {
return false;
}
}
con.close();
return true;
} catch (SQLException e) {
return false;
}
}
}