java+swing+mysql图书管理系统(附完整源代码)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
课程设计精品图书If理系统
书生
系统说明:本系统釆用eclipse开发,IDEA, eclipse, myedipse均可运行
界面采用swing实现
数据库:mysql.附sql代码,其余数据库可复制sql代码运行
数据库连接文件mysql-connector-java-8.0.16.jar
本系统的背景图片可根据自己的需求替换
项目分为管理员和普通用户两种角色
管理员有图书査询、图书借还、账户管理(修改密码、账户信息、借书记录)、图书管理(増加、修改、删除)的权限
普通用户有图书査询、图书借还、账户管理(修改密码、借书记录)的权限
项目结朴
-温图书系饨
>,JRE 基绽库(JavaSE-12]
IS src y .[« Dao
>dZl AdminDao.java
>® BookDao.java
><2)BorrowDao.java
>I/) DB.java
>El LandDao.java
v SB Test
>JZ) LandTest.java
击View
>ABorrowBookFace.java 通AccountMsgFacejava
>i£\ AddBookFace.java
>(2 AdminFace.java
>Lfi BookAdminFace.java
>® BookReturnFace.java
>Si BookSearc h Fac e.java
>DeleteBookFace.java
>JZ) LogonFace.java
>Si MainFace.java
>JZl UBorrowBookFace.java
><2)UpdateBookFace.java
>UpdatePswFace.java
>E) UserFace.java
> i引用的阵
y 4 datebase
圍tsglsys.sql
〜〜img。
admin.jpeg。
bg1.jpg。
login.jpg
—mainbg.jpg
y — lib
耳mysql-connector-java-8.0.16.jar
登录界面:
管理员登录:蘇号root,密码123123普通用户登录:账号123,密码123123
注册界面:
管理员主界面:
E W ill
fflHW
W
图书査询界面,
I 齐血IM BA* MKftW
图书查训
讷逸拝査询方式:
y松■.捜水
图书借还界面,
| w ・IMKA* WIHIH- <mw mnnw
图书借还
埔输入书号,
检室
竹名:作帝状妇
ifc«
账户管理界面:
图书管理界面:
图书管理
*MNHCa
WAIVKGU
M&NIISGft 添加图书界面:
添加图书
类别:膑弄类琳,
书名:______________ 2J
作者:
出版社:
价格:
确定
修改图书界面:
修改图书信息
15 ■;: I
类别:页逸择晒
书名:
作者:
出版社:
状态:。
馆
价格:
确定
账户值息界面:
账户信息
AH5记录界面:
诱盗拝A
改方式:
借书记录普通用户主界面:
普通用户際户管理界面:
账户管理背景图片,
数据库文件(tsglsys.Sql):
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS bookcategory*;
CREATE TABLE 'bookcategory' (
'Category' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 1 类别‘,
PRIMARY KEY ('Category') USING BTREE
)ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;
INSERT INTO 'bookcategory' VALUES ('军事');
INSERT INTO 'bookcategory' VALUES ('天文');
INSERT INTO 'bookcategory' VALUES ('学术');
INSERT INTO 'bookcategory' VALUES ('小说');
INSERT INTO 'bookcategory' VALUES ('文艺');
INSERT INTO 'bookcategory' VALUES ('科幻');
INSERT INTO 'bookcategory' VALUES ('经济‘);
DROP TABLE IF EXISTS booktable,;
CREATE TABLE 'booktable' (
'bookid' int(10) NOT NULL AUTOJNCREMENT COMMENT'书号‘,
'category' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' 类别','bookname' varchar(lOO) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT'书名,,
author' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT'作者,
'press' varchar(lOO) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT'出版社,
price' float(10, 2) NOT NULL COMMENT'价格
'state' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMEN「状态
PRIMARY KEY ( bookid*) USING BTREE,
INDEX 'category'('category') USING BTREE,
CONSTRAINT 'booktable_ibfk_l* FOREIGN KEY ('category') REFERENCES 'bookcategory' ( Category*) ON DELETE RESTRICT ON UPDATE CASCADE
)ENGINE = InnoDB AUTOJNCREMENT = 21 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;
INSERT INTO 'booktable VALUES (1,,学术。
'《JAVA程序设计教程》*,'刘志宏航空工业出版社)45.00,在馆,);
INSERT INTO 'booktable* VALUES (2,,学术〉,《软件工程》‘,'程成'机械工业出版社',31.50, * 在馆‘);
INSERT INTO 'booktable' VALUES (3,'学术* (计算机文化》'(美)帕森斯(Parsons JJf,'电子工业出版社28.00,,在馆》;
INSERT INTO 'booktable' VALUES (4,,文艺〉'《我在未来等你》','刘同','青年光影出版社36.50,,在馆‘);
INSERT INTO 'booktable' VALUES (5,'小说,《西游记》'吴承恩'岳麓出版社33.50,,在馆,);
INSERT INTO 'booktable* VALUES (6,'学术'《数据结构(c语言)》\ '严蔚敏清华大学出版社
"27.50,,在馆,);
INSERT INTO 'booktable' VALUES (7, ,学术。
1<C语言程序设计教程》*,'谭浩强‘清华大学出版社,,40.00,,在馆
INSERT INTO 'booktable VALUES (8,'学术《计算机文化基础》,,'李永红','对外经济贸易大学。
32.50,在馆,);
INSERT INTO'booktable'VALUES (9, ,学术J《数据库系统实现》/加西亚-莫利纳‘机械工业出版社',47.00, ,在馆》;
INSERT INTO 'booktable' VALUES (10,,文艺,'《数据库系统基础教程》'厄尔曼'机械工业出版社。
38.50,,在馆');
INSERT INTO 'booktable* VALUES (11,'学术J《数学思维导论》‘Keith Devlin1,'人民邮电出版枇
40.00,,在馆)
INSERT INTO 'booktable' VALUES (12,'学术‘《移动应用Ul设计必修课》‘,'余振华'人民邮电出版社36.00,,在馆');
INSERT INTO 'booktable' VALUES (13,,学术,1《快速软件开发》,史蒂夫•迈克康奈尔,,‘清华大学出版社*, 25.50/在馆,);
INSERT INTO 'booktable' VALUES (14,,科幻J《三体》‘刘慈欣‘重庆出版社31.00,,在馆
INSERT INTO booktable* VALUES (15, ,科幻,,'《海底两万里》\ ,镭尔•凡尔纳,,'译林出版社
32.50,,在馆
INSERT INTO 'booktable' VALUES (16,'军事‘《狼牙》'刘猛'北京联合出版公司35.50,,在馆》;
INSERT INTO ,booktable' VALUES (17,'天文'《宇宙的琴弦》'布赖恩•格林','湖南科学技术岀版社。
30.00,,在馆
INSERT INTO booktable VALUES (18,'经济,,'《货币经融学》'弗宙德里克・S•米什金'中国人民大学出版社60.00/在馆》;
DROP TABLE IF EXISTS 'borrowrecords';
CREATE TABLE 'borrowrecords* (
'id' int(10) NOT NULL AUTOJNCREMENT COMMEN「借书序列‘,
'user' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名,'bookid' int(10) NOT NULL COMMENT '书号‘,
'bookname' varchar(SO) CHARACTER SETutf8 COLLATE utf8_general_ci NOT NULL COMMENT, 书名',
'borrowtime' date NOT NULL COMMENT ‘借书时间',
'returntime* date NULL DEFAULT NULL COMMENT1还书时间',
'status' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '状态:PRIMARY KEY ('id') USING BTREE
)ENGINE = InnoDB AUTOJNCREMENT = 25 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;
DROP TABLE IF EXISTS 'usertable*;
CREATE TABLE 'usertable* (
'user' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名,,'studentid' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 1 学号‘,
'name' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT名
I
'password* varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' 密码',admin' int(10) NOT NULL COMMENT 否为管理员账户1为管理员,0为普通用户,耿认为0',
PRIMARY KEY ('user') USING BTREE
)ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;
user studentid name password admin
「123
|123 123 123123 0 j 1234 1234 1234 123123 0 root
root
root
123123
1
Dao 包下的 AdminDao.java :
package Dao; import java.sql.*;
import javax.swing.DOptionPane; public class AdminDao
INSERT INTO 'usertable' VALUES ('123', '123', '123', '123', 0); INSERT INTO 'usertable' VALUES ('root*, 'root*, 'root*, '123', 1); SET FOREIGN_KEY_CHECKS = 1;
ft®库表g
bookid 3c9o<y bookrumc author
prew
price Udtc ♦■■n 字术
《JAVAft 序釦球询孩
换2现出版吐
45.00 汛1 2 k <«nze>
E 工业出加 3150 StS 3字术 《计・叔化》
伊DgXPgom J“坦孑工业出如t
2800 STB 4 ftZ MR
■年光彫出或吐
3&5O StS
即恩
3150 E Category
6K 《EM 构(cms)
砂大竽岀版牡 27.SE
7字术 任厦EH 奶.t»;已狰
綺地大孕岀阪牡 40.00 E® 0
8字术 9M1
対咄疥倒月大学
32.50 E
9字术
tC®E WW SlMIlkttitttt
47.00 m 10 J7X 《以»5翌3砲 娅厄尔JI BUHk 出 CM
3a 50 E 学术
11字术 《蚊学专姥号沦〉
Keith Devtin
入印曲出扱吐 40.00 m 12字天 人出版吐
3600 ZBB 13学术
25.50 E 14冲 <=»)
或庆岀wt
31.00 ®S
15 瞬史》
版壮 32-SOEm 科幻
16 S9
旅合出版公5)
35.SO 17叔 《芥&3蜘
布1鴨花协
3000 阪
18竖济
中国人抵裂蛔之
60.00 &i
27 1234 bookid bookname borrowtime
returntime status 13《快速软件开发2019-12-25 2019-12-25
已还
28 root
1 CJAVA^yiSv 2019-12-25
id user
public static boolean sureuser(String user) {
Connection con = DB .connectDBO;
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from usertable where user = ?" try { preSql = con.prepareStatement(sqlStr);
preSql.setString(l, user);
rs = preSql.executeQuery();
boolean flag = false;
while(rs.next()) {
flag = true;
return true;
)
if(!flag) (
return false;
)
con.close();
return false;
} catch (SQLException e) (
return false;
})
public static void modifypass(String user,String password) Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "update usertable set password=? where user = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, password);
preSql.setString(2, user);
int ok = preSql.executeUpdate();
con.close();
) catch (SQLException e) {
}}
public static Boolean adduser(String user, String studentid, String name. String password) ( Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "insert into usertable values (?,?,?,?,0)";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, user);
preSql.setstring(2, studentid);
preSql.setString(3, name);
preSql.setString(4, password);
int ok = preSql.executeUpdate();
con.close();
return true;
} catch (SQLException e) (
JOptionPane.shoivMessageDiatog(null,"用户名已存在"' 警告",DOptionPane.MARNING_MESSAGE);
return false;
)
}}
BookDao.java:
package Dao;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.Default!ableModel;
public class BookDao {
public BookDao() {
}
public static void findcategory(JComboBox<String> box) ( Connection con = DB.connectDBO;
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from bookcategory";
try {
preSql = con.prepareStatement(sqlStr);
rs = preSql.executeQuery();
while (rs.next()) {
String category = rs.getString(l);
box.addltem(category);
con.close();
} catch (SQLException e) (
〃添加图书
public static void addbook(String category,String bookname,String author,String press,String price) { Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "insert into
booktable(category,bookname,author,press,price,state) values
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, category);
preSql.setstring(2, bookname);
preSql.setString(3, author);
preSql.setString(4, press);
preSql.setString(5, price);
preSql.setString(6, ”在馆”);
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,String price) (
Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "update booktable set category = ?
,bookname = ? ,author = ?,press = ? ,price = ?,state = ? where bookid =
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, category);
preSql.setstring(2, bookname);
preSql.setString(3, author);
preSql.setString(4, press);
preSql.setString(5, price);
preSql.setstring(6, state);
preSql.setlnt(7, bookid);
int ok = preSql.executeUpdate();
con.close();
) catch (SQLException e) {
})
〃删除图书
public static void deletebook(int bookid) {
Connection con = DB .connectDBO;
PreparedStatement preSql;
String sqlStr = "delete from booktable where bookid = ?" try { preSql = con.prepareStatement(sqlStr); preSql.setInt(l, bookid);
int ok = preSql.executeUpdate();
con.close();
} catch (SQLException e) (
})
//显示所有图书
public static void allbook(DefaultTableModel model) {
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from booktable";
try {
preSql = con.prepareStatement(sqlStr);
rs = preSql.executeQuery();
while (rs.next()) {
int bookid = rs.getlnt(l);
String category = rs.getString(2);
String bookname = rs.getString(3);
String author = rs.getString(4);
String press = rs.getString(5);
String price = rs.getString(6);
model.addRow(new Vector。
(Arrays.assist(bookid, category, bookname, author, press,price, state)));
)
con.close();
) catch (SQLException e) (
}}
//按类别査找图书
public static void findcategory(Def aultTableModel model. String CateGory) {
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
CateGory = + CateGory + "%”;
String sqlStr = "select * from booktable where category like ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, CateGory);
rs = preSql.executeQuery();
boolean flag = false;
while (rs.next()) {
flag = true;
int bookid = rs.getlnt(l);
String category = rs.getString(2);
String bookname = rs.getString(3);
String author = rs.getString(4);
String press = rs.getString(5);
String state = rs.getString(7);
model.addRow(new Vectoro(Arrays.asList(bookid, category, bookname, author, press, price,state)));
}
if Sag) {
DOptionPane. shoMMessageDia Log (null,"图书不存在
","警告",JOptionPane.UARNING_MESSAGE');
)
con.close();
) catch (SQLException e) (
}}
//按书号查找图书
public static void findbookid(DefaultTableModel model, int Bookid) (
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from booktable where bookid try {
preSql = con.prepareStatement(sqlStr); preSql.setInt(l, Bookid);
rs = preSql.executeQuery();
boolean flag = false;
while (rs.next()) (
flag = true;
int bookid = rs.getlnt(l);
String category = rs.getString(2);
String bookname = rs.getString(3);
String author = rs.getString(4);
String price = rs.getString(6);
String state = rs.getString(7);
model.addRow(new Vector<>(Arrays.as£ist(bookid, category, bookname, author, press, price,state)));
}
if (!flag) (
JOptionPane. showMessageDia Log (null,"图书不存在","警告”,JOptionPane.UARNING_MESSAGE);
)
con.close();
} catch (SQLException e) {
BorrowDao.java
package Dao;
import java.sql.*;
import java.sql.Date;
import java.util.*;
import javax.swing.table.Default!ableModel;
public class BorrowDao {
public BorrowDao() {
}
〃借阅图书
public static void Borrow(String user, int bookid. String bookname) {
Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "insert into borrowrecords(user,bookid,bookname,borrowtime,returntime,statu s) values (?,?,?,now(),null,?)";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, user);
preSql.setInt(2, bookid);
preSql.setString(3, bookname);
preSql.setString(4,"未还”);
int ok = preSql.executeUpdate();
con.close();
ChangeBorrouState(bookid);
} catch (SQLException e) {
}}
〃借阅图书修改图书状态
private static void ChangeBorrowState(int bookid) {
Connection con = DB .connectDBQ;
PreparedStatement preSql;
String sqlStr = "update booktable set state=? where bookid = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, ”外借”);
preSql.setlnt(2, bookid);
int ok = preSql.executeUpdate();
con.close();
) catch (SQLException e) {
}}
〃还书
public static void Return(String user, int bookid) {
Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "select now()";
ResultSet rs;
Date date=null;
try {
preSql = con.prepareStatement(sqlStr);
rs = preSql.executeQuery();
while(rs.next()) {
date = rs.getDate(l);
)
sqlStr = "update borrowrecords set returntime = ? where bookid = ? and user = ? and status = ?";
preSql = con.prepareStatement(sqlStr);
preSql.setDate(l, date);
preSql.setlnt(2, bookid);
preSql.setString(3, user);
preSql.setString(4,"未还”);
int ok = preSql.executeUpdate();
sqlStr = "update borrowrecords set status = ? where bookid = ? and user = ? and status = ?";
preSql = con.prepareStatement(sqlStr);
preSql.setString(l,"已还”);
preSql.setlnt(2, bookid);
preSql.setstring(3, user);
preSql.setString(4,"未还”);
ok = preSql.executeUpdate();
con.close();
ChangeReturnState(bookid);
} catch (SQLException e) {
})
〃还书图书修改图书状态
private static void ChangeReturnState(int bookid) {
Connection con = DB.connectDB();
PreparedStatement preSql;
String sqlStr = "update booktable set state=? where bookid = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l,"在馆”);
preSql.setInt(2, bookid);
int ok = preSql.executeUpdate();
con.close();
} catch (SQLException e) (
}}
〃比对还书
public static boolean comparison(String user,int bookid) {
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from borrowrecords where bookid = ? and status = ?";
try {
preSql = con.prepareStatement(sqlStr);
preSql.setInt(l, bookid);
preSql.setString(2,"未还”);
rs = preSql.executeQuery();
while (rs.next()) {
String user2 = rs.getString(2);
if(user2.equals(user)) {
return true;
)else {
return false;
}}
con.close();
return false;
) catch (SQLException e) {
return false;
})
public static void allborrow(DefaultTableModel model) (
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from borrowrecords";
try ( preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery();
while (rs.next()) {
String user = rs.getString(2);
int bookid = rs.getlnt(3);
String bookname = rs.getString(4);
Date date = rs.getDate(5);
Date date2 = rs.getDate(6);
String status = rs.getString(7);
model.addRow(new
Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;}
con.close();
) catch (SQLException e) {
}}
〃用户名借书记录
public static void userborrow(DefaultTableModel
model,String user) {
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from borrowrecords where user
=?”;
try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(1, user);
rs = preSql.executeQuery();
while (rs.next()) {
int bookid = rs.getlnt(3);
String bookname = rs.getString(4);
Date date = rs.getDate(5);
Date date2 = rs.getDate(6);
String status = rs.getString(7);
model.addRow(new
Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;}
con.close();
} catch (SQLException e) (
})
//书号借书记录
public static void bookidborrow(DefaultTableModel model,int bookid) ( Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from borrowrecords where
bookid =
try {
preSql = con.prepareStatement(sqlStr);
preSql.setInt(l, bookid);
rs = preSql.executeQuery();
while (rs.next()) {
String user = rs.getString(2);
String bookname = rs.getString(4);
Date date = rs.getDate(5);
Date date2 = rs.getDate(6);
String status = rs.getString(7);
model.addRow(new
Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;} con.close();
} catch (SQLException e) {}
})
DB.java(数据库连接类):
package Dao;
import java.sql.*;
public class DB {
public static Connection connectDB() {
String url = "jdbc:mysql://
localhost:3306/tsglsys?sepverTimezone=GMT%2B8";
try {
Class ./orA/ame("com.mysql. cj .jdbc. Driver");
} catch (Exception e) (
}
Connection con = null;
try {
con = DriverManager.getConnection(url, "root", "1234");
} catch (SQLException e) (
}
return con;
}}
LandDao.java:
package Dao;
import java.sql.*;
import javax.swing.JOptionPane;
public class LandDao (
public static Boolean test(String user. String password) (
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from usertable where user = ?" try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, user);
rs = preSql.executeQuery();
boolean flag = false;
while(rs.next()) {
flag = true;
String password2 = rs.getString(4);
if (!(password.equals(password2))) {
DOptionPane. shoMMessageDia Log (null,"密码错误"警告",JOptionPane .UARNING_MESSAGE);
return false;}}
if(!flag) (
JOptionPane. showMessageDia Log (null,"用户名不存在"'
"警告",JOptionPane.UARNING_MESSAGE);
return false;
)
con.close();
return true;
) catch (SQLException e) {
JOptionPane. showMessageDia Log (null,"用户名不存在"'"警告”,JOptionPane .MARNING_MESSAGE);
return false;
}}
〃确定是否为管理员
public static boolean sureadmin(String user) {
Connection con = DB.connectDB();
PreparedStatement preSql;
ResultSet rs;
String sqlStr = "select * from usertable where user = ?" try {
preSql = con.prepareStatement(sqlStr);
preSql.setString(l, user);
rs = preSql.executeQuery();
while(rs.next()) {
int admin = rs.getlnt(5);
if (admin==l) {
return true;
)else {
return false;
}}
con.close();
return true;
) catch (SQLException e) {
return false;
})}
Test 包LandTest.java:
package Test;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import ndDao;
import View.LogonFace;
import View.MainFace;
public class LandTest {
private JLabel jLabel = new J Label ("图书管理系统”);
private DLabel jLabel2 = new 3Label("用户名:");
private DLabel jLabel3 = new 3Label("密码:”);
private Font font = new Font("宋体Font.BOLD, 40);
private Font font2 = new Font("宋体”,Font.BOLD, 25);
private Font font3 = new Font("宋体",Font.SOLD, 20);
private DTextField field = new 3TextField(22);
private DPasswordField field2 = new 3PasswordField(22);
private JButton button = new J Button ("登陆”);
private JButton button2 = new JButton("注册”);
private3Panel jPanel = new JPanel();
private JPanel jPanel2 = new JPanel();
private JPanel jPanel3 = new3Panel();
private JPanel jPanel4 = new JPanel();
private JPanel jPanelS = new3Panel();
private JFrame frame = new J Frame ("登陆”);
private Dimension dimension = new Dimension(30, 30);
private Dimension dimension2 = new Dimension(100, 50); public String user; private String password;
public LandTest() {
frame .setTitle("登陆”);
frame.setSize(550, 500);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
Toolkit t = Toolkit.getDefauLtTooLkit^;
Image image = t.getlmage("img\\login.jpg");
frame.seticonimage(image);
addassembly();
transparent();
addEvent();
Icon i = new Imageicon("img\\login.jpg");
JLabel Label = new JLabel(i);
Label.setBounds(0, 0, 550, 500);
frame.add(Label);
frame.setResizable(false);
frame. setDef aultCloseOperation (J F name. EXIT_ON_CLOSE'); frame.setVisible(true);} private void addassembly() {
jLabel.setFont(font);
j Label2.setFont(font2);
j Label3.setFont(font2);
button.setFont(font3);
buttonZ.setFont(font3);
field.setFont(font3);
field2.setFont(font3);
field.setPreferredSize(dimension);
field2.setPreferredSize(dimension);
button.setPreferredSize(dimension2);
button2.set PreferredSize(dimension2); jPanel.add(jLabel);
jPanel2.add(jLabel2);
jPanel2.add(field);
jPanel3.add(j Label3);
jPanel3.add(field2);
jPanel4.add(button);
jPanels.add(button2);
jPanel.setBounds(0, 60, 550, 80); jPanel2.setBounds(0, 160, 550, 80); jPanel3.setBounds(0, 250, 550,
60);
jPanel4.setBounds(100, 325, 150, 80); jPanel5.setBounds(275, 325, 150, 80); fname.add(j Panel);
frame.add(jPanel2);
frame.add(jPanel3);
frame.add(jPanel4);
frame.add(jPanelS);}
private void transparent() (
jLabel.setOpaque(false);
jLabel2.setOpaque(false);
jLabel3.setOpaque(false);
field.setOpaque(false);
field2.setOpaque(f alse);
jPanel.setOpaque(false);
jPanel2.setOpaque(false);
jPanel3.setOpaque(false);
jPanel4.setOpaque(false);
jPanel5.setOpaque(false);)
private void addEvent() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
user = field.getText().trim();
password = f ield2.getText();
if(LandDao.test(user, password)) {
DOptionPane. shoMMessageDia Log (null f"登陆成功”);
frame.dispose();
new MainFace(user);
)else {
empty。
;
}}
});
button2.addActionListener(new ActionListener() (
public void actionPerformed(ActionEvent e) (
frame.dispose();
new LogonFace();)
});
}
private void empty() {
field. setText(,,H);
field2.setText("”);
}
public static void main(String[] args) (
new LandTest();
}}
View 包ABorrowBookFace.java:
package View;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
import Dao.BorrowDao;
public class ABorrowBookFace extends JFrame (
private DPanel jPanel = new JPanel();
private DLayeredPane jLayeredPane = new 3LayeredPane();
private JLabel jLabel = new J Label ("借书记录”);
private JLabel jLabel2 = new JLabel(,f请选择査询方式:“);
private DTextField field = new 3TextField(20);
private 3ComboBox<String> box = new 3ComboBox<String>();
private JButton button = new JButton("搜索”);
private Font font = new Font("宋体”,Font.BOLD, 40);
model = new DefaultTableModel(); private String s;
private int num;
public ABorrowBookFace() {
Icon i = new Imageicon("img\\bgl.jpg");
JLabel Label = new JLabel(i);
Label.setBounds(0, 0, 850, 100); setLayout(null);
setSize(850, 65。
);
setLocationRelativeTo(null);
jLabel.setFont(font);
j Label.setBounds(345, 80, 400, 100);
j Label2.setFont(font4);
jLabel2.setBounds(95, 140, 250, 30);
box. additem (“按照用户名查找”);
box. additem (”按照书号査找”);
box.setFont(font3);
box.setBounds(95, 175, 160, 30);
box.setOpaque(false);
field .setFont(font2);
field.setBackground(Color.cyan);
private Font font2 = new
Font("宋体“,Font.BOLD, 20); private Font font3 = new
Font("宋体",Font.SOLD, 18); private Font font4 = new Font (“宋体",Font.BOLD, 17);
public DefaultTableModel
field.setBounds(325, 175, 200, 30);
field.setOpaque(false);
button.setFont(font2);
button.setBounds(590, 173, 80, 35);
button.setBackground(Color.cyan);
button.setOpaque(false);
jPanel.add(j Label);
jPanel.add(jLabel2);
jPanel.add(box);
jPanel.add(field);
jPanel.add(button);
model.addColumn("用户名", new Vector<Integer>());
model.addColumn("书号",new Vector<Integer>()); model. addColumn("书名”,new Vector<Integer> ());
model.addColumn("借书日期",new Vector<Integer>()); model.addColumn("还书日期”,new Vector<Integer>());
model.addColumn("状态",new Vector<Integer>());
JTable jTable = new 3Table(model);
JScrollPane pane = new JScrollPane(jTable); pane.setBounds(80, 220, 690, 340);
jLayeredPane.add(pane);
BorrowDao.aLLborrou^model);
setTitle("借书记录“);
setResizable(false);
addEvent();
JTableHeader head = jTable.getTableHeader();
head.setPreferredSize(new Dimension(head.getWidth(),
30));
head.set Font(new Font("宋体",Font.BOLD, 20));
head.setBackground(Color.cyan);
jTable.setRowHeight(30);
jTable.setFont(new Font(”宋体”,Font.ROMAN_BASELINE f17));
DefaultTableCellRenderer renderer = new
DefaultTableCellRenderer();
renderer.setHorizontalAlignment(DefaultTableCellRenderer.C£NTER);
jTable.setDefaultRenderer(Object.class, renderer);
jPanel.setBounds(0, 0, 850, 250);
jPanel.setOpaque(false);
jPanel.setLayout(null);
setContentPane(jLayeredPane);
add(jPanel);
add(Label);
setVisible(true);
}
private void addEvent() (
s ="按照用户名査找”;
box.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) ( s = (String) e.getltem();。