forked from kongxin-github/Java_Library_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategory.java
More file actions
53 lines (46 loc) · 1.36 KB
/
Category.java
File metadata and controls
53 lines (46 loc) · 1.36 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
package database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
public class Category {
public Category() {
}
//添加类别
public static boolean addcategory(String category) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
String sqlStr = "insert into bookcategory values (?)";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, category);
int ok = preSql.executeUpdate();
con.close();
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "类别已存在", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
}
//修改类别
public static boolean setcategory(String category,String category2) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
String sqlStr = "update bookcategory set Category = ? where Category = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, category2);
preSql.setString(2, category);
int ok = preSql.executeUpdate();
con.close();
if(ok==0) {
JOptionPane.showMessageDialog(null, "类别不存在", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "类别不存在", "警告", JOptionPane.WARNING_MESSAGE);
return false;
}
}
}