forked from kongxin-github/Java_Library_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
90 lines (75 loc) · 2.21 KB
/
Book.java
File metadata and controls
90 lines (75 loc) · 2.21 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JComboBox;
public class Book {
public Book() {
}
//图书类别加入下拉框
public static void findcategory(JComboBox<String> box) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from bookcategory";
try {
preSql = con.prepareStatement(sqlStr);
rs = preSql.executeQuery();
while (rs.next()) {
String category = rs.getString(1);
box.addItem(category);
}
con.close();
} catch (SQLException e) {
}
}
//添加图书
public static void addbook(String category,String bookname,String author,String press) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
String sqlStr = "insert into booktable(category,bookname,author,press,state) values (?,?,?,?,?)";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, category);
preSql.setString(2, bookname);
preSql.setString(3, author);
preSql.setString(4, press);
preSql.setString(5, "在馆");
int ok = preSql.executeUpdate();
con.close();
} catch (SQLException e) {
}
}
//添加图书
public static void modifybook(int bookid,String category,String bookname,String author,String press,String state) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
String sqlStr = "update booktable set category = ? ,bookname = ? ,author = ?,press = ? ,state = ? where bookid = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, category);
preSql.setString(2, bookname);
preSql.setString(3, author);
preSql.setString(4, press);
preSql.setString(5, state);
preSql.setInt(6, bookid);
int ok = preSql.executeUpdate();
con.close();
} catch (SQLException e) {
}
}
//删除图书
public static void deletebook(int bookid) {
Connection con = ConnectDatabase.connectDB();
PreparedStatement preSql;
String sqlStr = "delete from booktable where bookid = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setInt(1, bookid);
int ok = preSql.executeUpdate();
con.close();
} catch (SQLException e) {
}
}
}