Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
昵称vwk2gnleae
Library management
Commits
3767b161
Commit
3767b161
authored
2 years ago
by
昵称vwk2gnleae
Browse files
Options
Download
Email Patches
Plain Diff
end
parent
0924ff71
main
No related merge requests found
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
.classpath
+0
-7
.classpath
.idea/dataSources.xml
+12
-0
.idea/dataSources.xml
.project
+0
-17
.project
bookmanagesys.sql
+83
-91
bookmanagesys.sql
src/won/db/DBConnect.java
+1
-1
src/won/db/DBConnect.java
src/won/model/Admin.java
+3
-3
src/won/model/Admin.java
src/won/model/Book.java
+31
-5
src/won/model/Book.java
src/won/model/BorrowRecord.java
+0
-4
src/won/model/BorrowRecord.java
src/won/page/AdminPage.java
+77
-0
src/won/page/AdminPage.java
src/won/page/BookPage.java
+16
-3
src/won/page/BookPage.java
src/won/page/BorrowRecordPage.java
+39
-26
src/won/page/BorrowRecordPage.java
src/won/page/Home.java
+56
-19
src/won/page/Home.java
src/won/query/AdminQuery.java
+79
-0
src/won/query/AdminQuery.java
src/won/query/BookQuery.java
+39
-9
src/won/query/BookQuery.java
src/won/query/BorrowRecordQuery.java
+13
-15
src/won/query/BorrowRecordQuery.java
with
449 additions
and
200 deletions
+449
-200
.classpath
deleted
100644 → 0
+
0
-
7
View file @
0924ff71
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
/>
<classpathentry
excluding=
"book/Record.java"
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"lib"
path=
"src/mysql-connector-java-5.1.0-bin.jar"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
This diff is collapsed.
Click to expand it.
.idea/dataSources.xml
0 → 100644
+
12
-
0
View file @
3767b161
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"DataSourceManagerImpl"
format=
"xml"
multifile-model=
"true"
>
<data-source
source=
"LOCAL"
name=
"@localhost"
uuid=
"b204f30c-c8a6-4386-9039-9355688edd3d"
>
<driver-ref>
mysql.8
</driver-ref>
<synchronize>
true
</synchronize>
<jdbc-driver>
com.mysql.cj.jdbc.Driver
</jdbc-driver>
<jdbc-url>
jdbc:mysql://localhost:3306
</jdbc-url>
<working-dir>
$ProjectFileDir$
</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.project
deleted
100644 → 0
+
0
-
17
View file @
0924ff71
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
BooksManagementSystem
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
</projectDescription>
This diff is collapsed.
Click to expand it.
bookmanagesys.sql
+
83
-
91
View file @
3767b161
/*
Navicat Premium Data Transfer
Source Server :
mysql-8.0数据库
Source Server :
root
Source Server Type : MySQL
Source Server Version : 8001
7
Source Server Version : 8001
6
Source Host : localhost:3306
Source Schema : bookmanage
Source Schema : bookmanage
sys
Target Server Type : MySQL
Target Server Version : 8001
7
Target Server Version : 8001
6
File Encoding : 65001
Date:
27
/0
2
/202
1 22:49:38
Date:
18
/0
5
/202
3 13:12:04
*/
/*
Navicat Premium Data Transfer
Source Server : mysql-8.0数据库
Source Server Type : MySQL
Source Server Version : 80017
Source Host : localhost:3306
Source Schema : bookmanage
Target Server Type : MySQL
Target Server Version : 80017
File Encoding : 65001
Date: 27/02/2021 19:16:26
*/
create
database
if
not
exists
bookmanagesys
;
use
bookmanagesys
;
DROP
TABLE
IF
EXISTS
`user`
;
CREATE
TABLE
`user`
(
`id`
bigint
AUTO_INCREMENT
,
`username`
varchar
(
20
),
`password`
varchar
(
20
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
;
insert
into
user
(
id
,
username
,
password
)
value
(
8
,
'xiaoli'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
9
,
'zhangyogn'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
10
,
'zhangming'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
11
,
'hexu'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
12
,
'yang'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
13
,
'wang'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
14
,
'zhang'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
15
,
'zhangzetian'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
16
,
'wangyang'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
17
,
'郭州乐沙'
,
'666666'
);
insert
into
user
(
id
,
username
,
password
)
value
(
18
,
'北冥有鱼'
,
'666666'
);
SET
NAMES
utf8mb4
;
SET
FOREIGN_KEY_CHECKS
=
0
;
-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP
TABLE
IF
EXISTS
`admin`
;
CREATE
TABLE
`admin`
(
`id`
bigint
(
100
)
NOT
NULL
AUTO_INCREMENT
,
`adminname`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`password`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
23
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Dynamic
;
-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT
INTO
`admin`
VALUES
(
1
,
'lu'
,
'96E79218965EB72C92A549DD5A330112'
);
-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP
TABLE
IF
EXISTS
`book`
;
CREATE
TABLE
`book`
(
`id`
bigint
NOT
NULL
AUTO_INCREMENT
,
`bookname`
varchar
(
50
),
`total`
int
(
10
),
`putaway`
date
,
`surplus`
int
(
10
),
PRIMARY
KEY
(
id
)
)
ENGINE
=
InnoDB
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
;
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
8
,
'高等数学1'
,
10
,
'2018-08-01'
,
9
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
9
,
'高等数学2'
,
11
,
'2018-08-01'
,
11
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
10
,
'Java'
,
12
,
'2019-08-10'
,
10
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
11
,
'java精彩编程200例'
,
13
,
'2018-09-08'
,
10
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
12
,
'高 等教 育'
,
14
,
'2018-08-01'
,
11
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
13
,
'java从入门到精通'
,
15
,
'2017-09-08'
,
8
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
14
,
'java从入门到精通'
,
15
,
'2017-09-08'
,
8
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
15
,
'商务英语'
,
12
,
'2018-10-08'
,
10
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
16
,
'计算机入门'
,
13
,
'2018-11-08'
,
10
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
17
,
'大学英语'
,
8
,
'2018-10-08'
,
1
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
18
,
'计算机'
,
4
,
'2017-11-08'
,
1
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
19
,
'入门到精通'
,
2
,
'2019-09-17'
,
1
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
20
,
'高等教育'
,
2
,
'2018-08-01'
,
1
);
INSERT
INTO
`book`
(
id
,
bookname
,
total
,
putaway
,
surplus
)
VALUES
(
21
,
'MTML'
,
1
,
'2018-08-01'
,
1
);
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`bookname`
varchar
(
50
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`total`
int
(
10
)
NULL
DEFAULT
NULL
,
`putaway`
date
NULL
DEFAULT
NULL
,
`surplus`
int
(
10
)
NULL
DEFAULT
NULL
,
`price`
int
(
50
)
NULL
DEFAULT
NULL
,
`author`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
29
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Dynamic
;
-- ----------------------------
-- Records of book
-- ----------------------------
INSERT
INTO
`book`
VALUES
(
32
,
'高等数学'
,
10
,
'2023-05-17'
,
10
,
10
,
'武忠祥'
);
INSERT
INTO
`book`
VALUES
(
33
,
'线性代数'
,
10
,
'2023-05-17'
,
10
,
10
,
'李永乐'
);
-- ----------------------------
-- Table structure for borrowrecord
-- ----------------------------
DROP
TABLE
IF
EXISTS
`borrowrecord`
;
CREATE
TABLE
`borrowrecord`
(
`id`
bigint
NOT
NULL
AUTO_INCREMENT
,
`bookid`
bigint
,
`userid`
bigint
,
`borrowdate`
date
,
`backdate`
date
,
`state`
varchar
(
20
),
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
;
use
bookmanagesys
;
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10004
,
8
,
8
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10006
,
9
,
9
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10008
,
10
,
10
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10010
,
11
,
11
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10014
,
12
,
12
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10016
,
13
,
13
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10018
,
14
,
14
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10020
,
15
,
15
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10022
,
16
,
16
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10024
,
17
,
17
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
INSERT
INTO
`borrowrecord`
(
id
,
bookid
,
userid
,
borrowdate
,
backdate
,
state
)
VALUES
(
10026
,
18
,
18
,
'2019-09-01'
,
'2019-10-01'
,
'已还'
);
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`bookid`
bigint
(
20
)
NULL
DEFAULT
NULL
,
`userid`
bigint
(
20
)
NULL
DEFAULT
NULL
,
`borrowdate`
date
NULL
DEFAULT
NULL
,
`backdate`
date
NULL
DEFAULT
NULL
,
`state`
varchar
(
20
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
10042
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Dynamic
;
-- ----------------------------
-- Records of borrowrecord
-- ----------------------------
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP
TABLE
IF
EXISTS
`user`
;
CREATE
TABLE
`user`
(
`uid`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
,
`username`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`password`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`realname`
varchar
(
100
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`createtime`
datetime
(
0
)
NULL
DEFAULT
NULL
,
`state`
int
(
11
)
NULL
DEFAULT
NULL
,
`mobile`
varchar
(
50
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
NULL
DEFAULT
NULL
,
`amount`
bigint
(
100
)
NULL
DEFAULT
NULL
,
PRIMARY
KEY
(
`uid`
)
USING
BTREE
,
UNIQUE
INDEX
`user_uid_uindex`
(
`uid`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
2
CHARACTER
SET
=
utf8
COLLATE
=
utf8_general_ci
ROW_FORMAT
=
Dynamic
;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT
INTO
`user`
VALUES
(
1
,
'user'
,
'96E79218965EB72C92A549DD5A330112'
,
NULL
,
'2023-05-17 20:53:22'
,
1
,
'111111'
,
180
);
INSERT
INTO
`user`
VALUES
(
5
,
'44'
,
'96e79218965eb72c92a549dd5a330112'
,
'1'
,
'2023-05-17 00:00:00'
,
1
,
'1'
,
0
);
SET
FOREIGN_KEY_CHECKS
=
1
;
This diff is collapsed.
Click to expand it.
src/won/db/DBConnect.java
+
1
-
1
View file @
3767b161
...
...
@@ -10,7 +10,7 @@ import java.sql.SQLException;
public
class
DBConnect
{
static
String
DB
=
"bookmanagesys"
;
static
String
username
=
"root"
;
static
String
password
=
"
666666
"
;
static
String
password
=
"
ljl18672013022
"
;
static
Connection
connection
=
null
;
public
static
Connection
getConnect
()
{
...
...
This diff is collapsed.
Click to expand it.
src/won/model/
User
.java
→
src/won/model/
Admin
.java
+
3
-
3
View file @
3767b161
...
...
@@ -3,14 +3,14 @@ package won.model;
/**
* 用户模型,与数据库表对应
*/
public
class
User
{
public
class
Admin
{
private
long
id
;
private
String
username
;
private
String
password
;
public
User
()
{
public
Admin
()
{
}
public
User
(
long
id
,
String
username
,
String
password
)
{
public
Admin
(
long
id
,
String
username
,
String
password
)
{
this
.
id
=
id
;
this
.
username
=
username
;
this
.
password
=
password
;
...
...
This diff is collapsed.
Click to expand it.
src/won/model/Book.java
+
31
-
5
View file @
3767b161
package
won.model
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.List
;
import
static
java
.
lang
.
System
.
out
;
...
...
@@ -13,6 +15,8 @@ public class Book {
private
String
putaway
;
private
int
tatal
;
private
int
surplus
;
private
long
price
;
private
String
author
;
public
Book
()
{
...
...
@@ -25,6 +29,15 @@ public class Book {
this
.
surplus
=
tatal
;
}
public
Book
(
String
bookname
,
String
putaway
,
int
total
,
long
price
,
String
author
)
{
this
.
bookname
=
bookname
;
this
.
putaway
=
putaway
;
this
.
tatal
=
total
;
this
.
surplus
=
total
;
this
.
price
=
price
;
this
.
author
=
author
;
}
public
static
Book
byId
(
long
id
)
{
Book
book
=
new
Book
();
book
.
setId
(
id
);
...
...
@@ -42,9 +55,9 @@ public class Book {
public
static
void
display
(
Book
book
,
boolean
isExistTitle
)
{
if
(
isExistTitle
)
{
out
.
println
(
"ID\t书名\t上架日期\t总数\t可借数量"
);
out
.
println
(
"ID\t书名\t上架日期\t总数\t可借数量
\t售价\t作者
"
);
}
out
.
println
(
book
.
getId
()+
"\t"
+
book
.
getBookname
()+
"\t"
+
book
.
getPutaway
()+
"\t"
+
book
.
getTatal
()+
"\t"
+
book
.
getSurplus
());
out
.
println
(
book
.
getId
()+
"\t"
+
book
.
getBookname
()+
"\t"
+
book
.
getPutaway
()+
"\t"
+
book
.
getTatal
()+
"\t"
+
book
.
getSurplus
()
+
"\t"
+
book
.
getPrice
()+
"\t"
+
book
.
getAuthor
()
);
}
public
static
Book
byBookname
(
String
bookName
)
{
...
...
@@ -53,12 +66,14 @@ public class Book {
return
book
;
}
public
Book
(
long
id
,
String
bookname
,
String
putaway
,
int
tatal
,
int
surplus
)
{
public
Book
(
long
id
,
String
bookname
,
String
putaway
,
int
tatal
,
int
surplus
,
int
price
,
String
author
)
{
this
.
id
=
id
;
this
.
bookname
=
bookname
;
this
.
putaway
=
putaway
;
this
.
tatal
=
tatal
;
this
.
surplus
=
surplus
;
this
.
price
=
price
;
this
.
author
=
author
;
}
public
long
getId
()
{
...
...
@@ -101,8 +116,19 @@ public class Book {
this
.
surplus
=
surplus
;
}
public
long
getPrice
()
{
return
price
;
}
public
void
setPrice
(
long
price
)
{
this
.
price
=
price
;
}
public
String
getAuthor
()
{
return
author
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello World!"
)
;
public
void
setAuthor
(
String
author
)
{
this
.
author
=
author
;
}
}
This diff is collapsed.
Click to expand it.
src/won/model/BorrowRecord.java
+
0
-
4
View file @
3767b161
...
...
@@ -86,8 +86,4 @@ public class BorrowRecord {
this
.
state
=
state
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello World!"
);
}
}
This diff is collapsed.
Click to expand it.
src/won/page/
User
Page.java
→
src/won/page/
Admin
Page.java
+
77
-
0
View file @
3767b161
package
won.page
;
import
won.model.Admin
;
import
won.model.User
;
import
won.query.AdminQuery
;
import
won.query.UserQuery
;
import
java.util.Scanner
;
...
...
@@ -8,36 +10,25 @@ import java.util.Scanner;
import
static
java
.
lang
.
System
.
out
;
/**
* 对于
User
的操作窗口,主要调用query.BorrowRecordQuery里面的查询方法
* 对于
admin
的操作窗口,主要调用query.BorrowRecordQuery里面的查询方法
*/
public
class
UserPage
{
public
class
AdminPage
{
static
Scanner
input
=
new
Scanner
(
System
.
in
);
public
User
Page
()
{
public
Admin
Page
()
{
}
public
static
User
l
oginConsole
()
{
User
user
=
null
;
public
static
Admin
adminL
oginConsole
()
{
Admin
admin
=
null
;
System
.
out
.
println
(
"****************欢迎使用图书管理系统***************"
);
while
(
true
)
{
System
.
out
.
println
(
"********************账户登录********************"
);
out
.
println
(
"提示:【1】已有账号,请登录 【2】没有账号,请注册"
);
out
.
print
(
"请选择方式:"
);
user
=
null
;
Scanner
input
=
new
Scanner
(
System
.
in
);
String
select
=
input
.
nextLine
();
out
.
print
(
"账号:"
);
String
userid
=
input
.
nextLine
();
System
.
out
.
println
(
"********************管理员界面********************"
);
out
.
print
(
"管理员账号:"
);
String
uid
=
input
.
nextLine
();
out
.
print
(
"密码:"
);
String
password
=
input
.
nextLine
();
switch
(
select
)
{
case
"1"
:
user
=
UserQuery
.
queryUser
(
userid
,
password
);
break
;
case
"2"
:
user
=
UserQuery
.
registerUser
(
userid
,
password
);
break
;
}
if
(
user
!=
null
)
{
admin
=
AdminQuery
.
queryAdmin
(
uid
,
password
);
if
(
admin
!=
null
)
{
out
.
println
(
"登录成功!"
);
break
;
}
else
{
...
...
@@ -50,21 +41,34 @@ public class UserPage {
}
}
}
return
user
;
return
admin
;
}
public
static
void
addAmount
(){
out
.
println
(
"********************充值账户********************"
);
out
.
println
(
"提示:【1】充值【2】取消"
);
int
select
=
Integer
.
parseInt
(
input
.
nextLine
());
if
(
select
==
1
){
out
.
println
(
"请输入用户id:"
);
long
uid
=
Integer
.
parseInt
(
input
.
nextLine
());
out
.
println
(
"请输入充值金额:"
);
long
amount
=
Integer
.
parseInt
(
input
.
nextLine
());
AdminQuery
.
addAmount
(
uid
,
amount
);
out
.
println
(
"充值成功!"
);
}
else
{
out
.
println
(
"充值失败!"
);
}
}
//管理员修改用户密码
public
static
User
resetPassword
()
{
System
.
out
.
println
(
"********************重置密码********************"
);
Scanner
input
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"请输入原有的账号:"
);
String
username
=
input
.
nextLine
();
out
.
print
(
"请输入原有的密码:"
);
String
password
=
input
.
nextLine
();
User
user
=
UserQuery
.
queryUser
(
username
,
password
);
System
.
out
.
print
(
"请输入用户的账号:"
);
String
userName
=
input
.
nextLine
();
User
user
=
UserQuery
.
queryUser
(
userName
);
if
(
user
!=
null
)
{
out
.
print
(
"请输入新密码:"
);
String
newPassword
=
input
.
nextLine
();
UserQuery
.
resetPassword
(
user
.
get
I
d
(),
newPassword
);
UserQuery
.
resetPassword
(
user
.
get
Ui
d
(),
newPassword
);
}
else
{
out
.
println
(
"身份验证失败!"
);
}
...
...
This diff is collapsed.
Click to expand it.
src/won/page/BookPage.java
+
16
-
3
View file @
3767b161
...
...
@@ -59,7 +59,11 @@ public class BookPage {
String
bookname
=
input
.
nextLine
();
out
.
print
(
"请输入数量:"
);
int
total
=
Integer
.
parseInt
(
input
.
nextLine
());
Book
book
=
new
Book
(
bookname
,
putaway
,
total
);
out
.
print
(
"请输入书价:"
);
long
price
=
Integer
.
parseInt
(
input
.
nextLine
());
out
.
print
(
"请输入作者:"
);
String
author
=
input
.
nextLine
();
Book
book
=
new
Book
(
bookname
,
putaway
,
total
,
price
,
author
);
BookQuery
.
addBook
(
book
);
}
...
...
@@ -69,8 +73,9 @@ public class BookPage {
List
<
Book
>
bookList
=
BookQuery
.
queryTodayBook
();
if
(!
bookList
.
isEmpty
()){
Book
.
diaplay
(
bookList
);
}
else
{
System
.
out
.
println
(
"提示:今日暂无新书!"
);
}
System
.
out
.
println
(
"提示:今日暂无新书!"
);
}
public
static
void
modifyBook
()
{
...
...
@@ -89,7 +94,7 @@ public class BookPage {
book
=
bookList
.
get
(
0
);
while
(
true
)
{
Book
.
display
(
book
,
true
);
System
.
out
.
println
(
"替换提示:【1】书名【2】日期【3】总数量【4】可借数量"
);
System
.
out
.
println
(
"替换提示:【1】书名【2】日期【3】总数量【4】可借数量
【5】价格【6】作者
"
);
System
.
out
.
print
(
"选择:"
);
int
n
=
Integer
.
parseInt
(
input
.
nextLine
());
switch
(
n
)
{
...
...
@@ -109,6 +114,14 @@ public class BookPage {
out
.
print
(
"替换可借数量为:"
);
book
.
setSurplus
(
Integer
.
parseInt
(
input
.
nextLine
()));
break
;
case
5
:
out
.
print
(
"替换价格为:"
);
book
.
setPrice
(
Integer
.
parseInt
(
input
.
nextLine
()));
break
;
case
6
:
out
.
print
(
"替换作者名字为:"
);
book
.
setAuthor
(
input
.
nextLine
());
break
;
}
out
.
println
(
"是否继续修改:【1】继续,请输入1 【2】返回,请按其他任意键"
);
out
.
print
(
"请选择:"
);
...
...
This diff is collapsed.
Click to expand it.
src/won/page/BorrowRecordPage.java
+
39
-
26
View file @
3767b161
package
won.page
;
import
won.db.DBConnect
;
import
won.model.Book
;
import
won.model.BorrowRecord
;
import
won.model.QueryMode
;
import
won.model.User
;
import
won.model.*
;
import
won.query.AdminQuery
;
import
won.query.BookQuery
;
import
won.query.BorrowRecordQuery
;
import
won.query.UserQuery
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.util.*
;
import
static
java
.
lang
.
System
.
in
;
import
static
java
.
lang
.
System
.
out
;
/**
...
...
@@ -25,7 +25,7 @@ public class BorrowRecordPage {
}
public
static
void
borrowBookDetail
(
User
user
)
{
public
static
void
borrowBookDetail
()
{
System
.
out
.
println
(
"********************借阅图书********************"
);
while
(
true
)
{
System
.
out
.
println
(
"功能选项:【1】用户借书\t【2】查看借阅记录"
);
...
...
@@ -33,10 +33,10 @@ public class BorrowRecordPage {
String
selectItem
=
input
.
nextLine
();
switch
(
selectItem
)
{
case
"1"
:
borrowBook
(
user
);
borrowBook
();
break
;
case
"2"
:
queryBorrowRecord
(
user
);
queryBorrowRecord
();
break
;
}
out
.
println
(
"是否继续当前任务:【1】继续,请输入1\t 【2】返回,请输入Enter"
);
...
...
@@ -47,7 +47,25 @@ public class BorrowRecordPage {
}
}
}
public
static
void
borrowBook
(
User
user
){
public
static
void
borrowBookDetail
(
User
user
)
{
System
.
out
.
println
(
"--------------------您的借阅记录--------------------"
);
Connection
connection
=
DBConnect
.
getConnect
();
PreparedStatement
preparedStatement
=
null
;
ResultSet
resultSet
=
null
;
String
sql
=
null
;
List
<
BorrowRecord
>
borrowRecords
=
new
LinkedList
<>();
borrowRecords
=
BorrowRecordQuery
.
queryBorrowRecordByUserId
(
user
.
getUid
());
if
(!
borrowRecords
.
isEmpty
())
{
out
.
println
(
"查询到如下记录:"
);
for
(
int
i
=
0
;
i
<
borrowRecords
.
size
();
i
++)
{
BorrowRecord
.
display
(
borrowRecords
.
get
(
i
),
i
==
0
);
}
}
else
{
out
.
println
(
"没有查到相关记录!"
);
}
}
public
static
void
borrowBook
(){
List
<
Book
>
bookList
=
new
LinkedList
<>();
boolean
isAvailable
=
false
;
QueryMode
queryMode
=
null
;
...
...
@@ -73,13 +91,16 @@ public class BorrowRecordPage {
}
if
(
isAvailable
)
{
Book
book
=
bookList
.
get
(
0
);
Book
.
display
(
book
,
true
);
Book
.
display
(
book
,
true
);
System
.
out
.
println
(
"借书人Id:"
);
long
userId
=
input
.
nextLong
();
System
.
out
.
println
(
"提示:【1】借阅【2】取消"
);
System
.
out
.
print
(
"选择:"
);
int
select
=
Integer
.
parseInt
(
input
.
next
Line
()
);
if
(
select
==
1
)
{
int
select
=
input
.
next
Int
(
);
if
(
select
==
1
&&
UserQuery
.
queryUserById
(
userId
)
!=
null
&&
book
.
getPrice
()
<=
UserQuery
.
queryUserAmount
(
userId
)
)
{
//减少可借数量
BorrowRecordQuery
.
decreaseBookSurplus
(
book
,
queryMode
);
AdminQuery
.
decreaseBookAmount
(
userId
,
book
.
getPrice
());
//添加借阅记录
Date
date
=
new
Date
();
Calendar
calendar
=
Calendar
.
getInstance
();
...
...
@@ -89,7 +110,7 @@ public class BorrowRecordPage {
String
borrowdate
=
String
.
format
(
"%tF"
,
date
);
BorrowRecord
borrowRecord
=
new
BorrowRecord
();
borrowRecord
.
setBookid
(
book
.
getId
());
borrowRecord
.
setUserid
(
user
.
getId
()
);
borrowRecord
.
setUserid
(
user
Id
);
borrowRecord
.
setBorrowdate
(
borrowdate
);
borrowRecord
.
setBackdate
(
backdate
);
BorrowRecordQuery
.
addBorrowRecord
(
borrowRecord
);
...
...
@@ -97,27 +118,20 @@ public class BorrowRecordPage {
}
else
{
out
.
println
(
"借书失败!"
);
}
}
else
{
}
else
{
out
.
println
(
"没有查询到相应图书"
);
}
}
public
static
void
queryBorrowRecord
(
User
user
)
{
public
static
void
queryBorrowRecord
()
{
System
.
out
.
println
(
"--------------------借阅记录--------------------"
);
out
.
println
(
"功能:【1】查看当前借阅记录\t【2】查看所有记录"
);
out
.
print
(
"请选择:"
);
int
select
=
Integer
.
parseInt
(
input
.
nextLine
());
Connection
connection
=
DBConnect
.
getConnect
();
PreparedStatement
preparedStatement
=
null
;
ResultSet
resultSet
=
null
;
String
sql
=
null
;
List
<
BorrowRecord
>
borrowRecords
=
new
LinkedList
<>();
if
(
select
==
1
)
{
borrowRecords
=
BorrowRecordQuery
.
queryBorrowRecordByUserId
(
user
.
getId
());
}
else
if
(
select
==
2
)
{
borrowRecords
=
BorrowRecordQuery
.
queryAllBorrowRecord
();
}
borrowRecords
=
BorrowRecordQuery
.
queryAllBorrowRecord
();
if
(!
borrowRecords
.
isEmpty
())
{
out
.
println
(
"查询到如下记录:"
);
for
(
int
i
=
0
;
i
<
borrowRecords
.
size
();
i
++)
{
...
...
@@ -144,9 +158,9 @@ public class BorrowRecordPage {
}
}
public
static
void
returnBook
(
User
user
)
{
public
static
void
returnBook
()
{
System
.
out
.
println
(
"********************图书归还********************"
);
List
<
BorrowRecord
>
records
=
BorrowRecordQuery
.
queryBorrowRecord
ByUserId
(
user
.
getId
()
);
List
<
BorrowRecord
>
records
=
BorrowRecordQuery
.
query
All
BorrowRecord
(
);
if
(!
records
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
records
.
size
();
i
++)
{
BorrowRecord
.
display
(
records
.
get
(
i
),
i
==
0
);
...
...
@@ -158,10 +172,9 @@ public class BorrowRecordPage {
if
(!
BorrowRecordQuery
.
isOverDate
(
borrowRecord
))
{
BookQuery
.
increaseBookSurplus
(
borrowRecord
.
getBookid
());
borrowRecord
.
setState
(
"已还"
);
BorrowRecordQuery
.
updateBorrowRecord
(
borrowRecord
);
}
else
{
out
.
println
(
"借阅逾期,请到服务台归还"
+
user
);
out
.
println
(
"借阅逾期,请到服务台归还"
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/won/page/Home.java
+
56
-
19
View file @
3767b161
package
won.page
;
import
won.model.Admin
;
import
won.model.User
;
import
won.page.BookPage
;
import
won.page.BorrowRecordPage
;
import
won.page.UserPage
;
import
won.query.UserQuery
;
import
java.util.Scanner
;
...
...
@@ -16,23 +15,50 @@ public class Home {
public
Home
()
{
//测试账号
//User user = new User(8,"xiali","111111");
//进行登录,登录成功则返回一个用户实体
User
user
=
UserPage
.
loginConsole
();
//Admin admin = new Admin(lu,"111111");
//User user = new User(w,"111111");
//进行登录,登录成功则返回一个管理员或用户实体
out
.
println
(
"****************欢迎使用图书管理系统***************"
);
out
.
println
(
"【0】管理员登录 \t 【1】用户登陆"
);
int
selectOpe
=
Integer
.
parseInt
(
input
.
nextLine
());
Admin
admin
=
null
;
User
user
=
null
;
while
(
true
){
if
(
selectOpe
==
0
){
admin
=
AdminPage
.
adminLoginConsole
();
break
;
}
else
if
(
selectOpe
==
1
){
user
=
UserPage
.
userLoginConsole
();
break
;
}
else
{
out
.
println
(
"输入错误,请重新输入!"
);
}
}
while
(
true
)
{
out
.
println
(
"*******************图书管理系统 ******************"
);
out
.
println
(
"* 【1】今日新书 *"
);
out
.
println
(
"* 【2】查询图书 *"
);
out
.
println
(
"* 【3】借阅图书 *"
);
out
.
println
(
"* 【4】归还图书 *"
);
out
.
println
(
"* 【5】添加新书 *"
);
out
.
println
(
"* 【6】修改图书 *"
);
out
.
println
(
"* 【7】删除图书 *"
);
out
.
println
(
"* 【8】重置密码 *"
);
out
.
println
(
"* 【3】修改密码 *"
);
if
(
selectOpe
==
0
)
{
out
.
println
(
"* 【4】借阅图书 *"
);
out
.
println
(
"* 【5】归还图书 *"
);
out
.
println
(
"* 【6】添加新书 *"
);
out
.
println
(
"* 【7】修改图书 *"
);
out
.
println
(
"* 【8】删除图书 *"
);
out
.
println
(
"* 【9】充值账户 *"
);
}
else
{
out
.
println
(
"* 【4】借书记录 *"
);
}
out
.
println
(
"* 【0】退出系统 *"
);
out
.
println
(
"*************************************************"
);
out
.
print
(
"请选择功能:"
);
String
select
=
input
.
nextLine
();
while
(
selectOpe
==
1
&&
Integer
.
parseInt
(
select
)
>
4
){
out
.
println
(
"输入错误,请重新输入!"
);
select
=
input
.
nextLine
();
}
switch
(
select
)
{
case
"1"
:
BookPage
.
getLatestBook
();
...
...
@@ -41,23 +67,34 @@ public class Home {
BookPage
.
queryBook
();
break
;
case
"3"
:
BorrowRecordPage
.
borrowBookDetail
(
user
);
if
((
user
==
null
)){
AdminPage
.
resetPassword
();
}
else
{
UserPage
.
resetPassword
(
user
.
getUsername
());
}
break
;
case
"4"
:
BorrowRecordPage
.
returnBook
(
user
);
if
(
user
==
null
){
BorrowRecordPage
.
borrowBookDetail
();
}
else
{
BorrowRecordPage
.
borrowBookDetail
(
user
);
}
break
;
case
"5"
:
BookPage
.
addBook
();
assert
admin
!=
null
;
BorrowRecordPage
.
returnBook
();
break
;
case
"6"
:
BookPage
.
modify
Book
();
BookPage
.
add
Book
();
break
;
case
"7"
:
BookPage
.
delete
Book
();
BookPage
.
modify
Book
();
break
;
case
"8"
:
User
newUser
=
UserPage
.
resetPassword
();
user
=
newUser
==
null
?
user:
newUser
;
BookPage
.
deleteBook
();
break
;
case
"9"
:
AdminPage
.
addAmount
();
break
;
case
"0"
:
out
.
println
(
"*******************已退出系统!!!*****************"
);
...
...
This diff is collapsed.
Click to expand it.
src/won/query/
User
Query.java
→
src/won/query/
Admin
Query.java
+
79
-
0
View file @
3767b161
package
won.query
;
import
won.db.DBConnect
;
import
won.model.User
;
import
won.model.Admin
;
import
won.model.Book
;
import
won.model.QueryMode
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
...
...
@@ -10,42 +14,25 @@ import java.sql.SQLException;
import
static
java
.
lang
.
System
.
out
;
/**
* 提供操作数据库表
user
的方法,提供各种查询,将数据库数据转为
User
对象模型
* 提供操作数据库表
admin
的方法,提供各种查询,将数据库数据转为
Admin
对象模型
*/
public
class
User
Query
{
public
User
Query
()
{
public
class
Admin
Query
{
public
Admin
Query
()
{
}
public
static
void
resetPassword
(
long
userid
,
String
newpassword
)
{
PreparedStatement
prestmt
=
null
;
try
{
String
sql
=
"update user SET password=? where id=?"
;
prestmt
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
prestmt
.
setString
(
1
,
newpassword
);
prestmt
.
setLong
(
2
,
userid
);
int
n
=
prestmt
.
executeUpdate
();
if
(
prestmt
!=
null
)
{
prestmt
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"修改密码成功!"
);
}
public
static
User
queryUser
(
String
username
,
String
password
)
{
public
static
Admin
queryAdmin
(
String
adminName
,
String
password
)
{
ResultSet
resultSet
=
null
;
PreparedStatement
prestmt
=
null
;
User
user
=
null
;
Admin
admin
=
null
;
try
{
String
sql
=
"SELECT * FROM
user
WHERE
user
name = ? AND password =
?
"
;
String
sql
=
"SELECT * FROM
admin
WHERE
admin
name = ? AND password =
md5(?)
"
;
prestmt
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
prestmt
.
setString
(
1
,
usern
ame
);
prestmt
.
setString
(
1
,
adminN
ame
);
prestmt
.
setString
(
2
,
password
);
resultSet
=
prestmt
.
executeQuery
();
if
(
resultSet
.
next
())
{
long
id
=
resultSet
.
getLong
(
"id"
);
user
=
new
User
(
id
,
usern
ame
,
password
);
admin
=
new
Admin
(
id
,
adminN
ame
,
password
);
}
if
(
resultSet
!=
null
)
{
...
...
@@ -57,38 +44,36 @@ public class UserQuery {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
user
;
return
admin
;
}
/**
* 用户账号已存在或注册失败返回 null,成功则返回User对象
**/
public
static
User
registerUser
(
String
username
,
String
password
)
{
out
.
println
(
"正在进行注册..."
);
User
user
=
null
;
if
(
queryUser
(
username
,
password
)
!=
null
)
{
out
.
println
(
"用户已存在,请直接登录!"
);
return
null
;
public
static
void
addAmount
(
long
uid
,
long
amount
)
{
PreparedStatement
prestmt
=
null
;
try
{
String
sql
=
"update user set amount = amount + ? where uid = ? "
;
prestmt
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
prestmt
.
setLong
(
1
,
amount
);
prestmt
.
setLong
(
2
,
uid
);
prestmt
.
executeUpdate
();
if
(
prestmt
!=
null
)
{
prestmt
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
PreparedStatement
preparedStatement
=
null
;
String
sql
=
null
;
boolean
isSuccess
=
false
;
}
public
static
void
decreaseBookAmount
(
long
uid
,
long
amount
)
{
PreparedStatement
prestmt
=
null
;
try
{
sql
=
"insert into user (username,password) values(?,?)"
;
preparedStatement
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
preparedStatement
.
setString
(
1
,
username
);
preparedStatement
.
setString
(
2
,
password
);
int
n
=
preparedStatement
.
executeUpdate
();
if
(
n
==
1
)
{
user
=
queryUser
(
username
,
password
);
System
.
out
.
println
(
"注册成功!"
);
}
else
{
System
.
out
.
println
(
"注册失败!"
);
String
sql
=
"update user set amount = amount - ? where uid = ? "
;
prestmt
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
prestmt
.
setLong
(
1
,
amount
);
prestmt
.
setLong
(
2
,
uid
);
prestmt
.
executeUpdate
();
if
(
prestmt
!=
null
)
{
prestmt
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
user
;
}
}
This diff is collapsed.
Click to expand it.
src/won/query/BookQuery.java
+
39
-
9
View file @
3767b161
...
...
@@ -68,7 +68,9 @@ public class BookQuery {
int
total
=
resultSet
.
getInt
(
"total"
);
String
indate
=
resultSet
.
getString
(
"putaway"
);
int
surplus
=
resultSet
.
getInt
(
"surplus"
);
bookList
.
add
(
new
Book
(
id
,
bookname
,
indate
,
total
,
surplus
));
int
price
=
resultSet
.
getInt
(
"price"
);
String
author
=
resultSet
.
getString
(
"author"
);
bookList
.
add
(
new
Book
(
id
,
bookname
,
indate
,
total
,
surplus
,
price
,
author
));
}
}
catch
(
SQLException
e
){
out
.
println
(
e
);
...
...
@@ -77,14 +79,16 @@ public class BookQuery {
}
public
static
void
updateBook
(
Book
book
)
{
Connection
connection
=
DBConnect
.
getConnect
();
String
sql
=
"UPDATE book SET bookname=?,total=?,putaway=?,surplus=? WHERE id = ?"
;
String
sql
=
"UPDATE book SET bookname=?,total=?,putaway=?,surplus=?
,price=?,author=?
WHERE id = ?"
;
try
{
PreparedStatement
prestmt
=
connection
.
prepareStatement
(
sql
);
prestmt
.
setString
(
1
,
book
.
getBookname
());
prestmt
.
setInt
(
2
,
book
.
getTatal
());
prestmt
.
setString
(
3
,
book
.
getPutaway
());
prestmt
.
setInt
(
4
,
book
.
getSurplus
());
prestmt
.
setLong
(
5
,
book
.
getId
());
prestmt
.
setLong
(
5
,
book
.
getPrice
());
prestmt
.
setString
(
6
,
book
.
getAuthor
());
prestmt
.
setLong
(
7
,
book
.
getId
());
prestmt
.
executeUpdate
();
if
(
prestmt
!=
null
)
{
prestmt
.
close
();
...
...
@@ -101,12 +105,14 @@ public class BookQuery {
Connection
connection
=
DBConnect
.
getConnect
();
PreparedStatement
prestmt
=
null
;
try
{
String
sql
=
"insert into book (bookname,putaway,total,surplus) values(?,?,?,?)"
;
String
sql
=
"insert into book (bookname,putaway,total,surplus
,price,author
) values(?,?,?,?
,?,?
)"
;
prestmt
=
connection
.
prepareStatement
(
sql
);
prestmt
.
setString
(
1
,
book
.
getBookname
());
prestmt
.
setString
(
2
,
book
.
getPutaway
());
prestmt
.
setInt
(
3
,
book
.
getTatal
());
prestmt
.
setInt
(
4
,
book
.
getSurplus
());
prestmt
.
setLong
(
5
,
book
.
getPrice
());
prestmt
.
setString
(
6
,
book
.
getAuthor
());
prestmt
.
executeUpdate
();
if
(
prestmt
!=
null
)
{
prestmt
.
close
();
...
...
@@ -210,20 +216,22 @@ public class BookQuery {
int
total
=
resultSet
.
getInt
(
"total"
);
String
putaway
=
resultSet
.
getString
(
"putaway"
);
int
surplus
=
resultSet
.
getInt
(
"surplus"
);
bookList
.
add
(
new
Book
(
id
,
bookname
,
putaway
,
total
,
surplus
));
int
price
=
resultSet
.
getInt
(
"price"
);
String
author
=
resultSet
.
getString
(
"author"
);
bookList
.
add
(
new
Book
(
id
,
bookname
,
putaway
,
total
,
surplus
,
price
,
author
));
}
}
catch
(
SQLException
e
)
{
out
.
println
(
e
);
}
return
bookList
;
}
public
static
void
increaseBookSurplus
(
long
book
i
d
)
{
public
static
void
increaseBookSurplus
(
long
book
I
d
)
{
PreparedStatement
preparedStatement
=
null
;
String
sql
=
null
;
try
{
sql
=
"update book set surplus=surplus+1
and
id=?"
;
sql
=
"update book set surplus=surplus+1
where
id=?"
;
preparedStatement
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
preparedStatement
.
setLong
(
1
,
book
i
d
);
preparedStatement
.
setLong
(
1
,
book
I
d
);
preparedStatement
.
executeUpdate
();
}
catch
(
SQLException
e
)
{
...
...
@@ -231,7 +239,29 @@ public class BookQuery {
}
out
.
println
(
"图书数量已更新! = "
);
}
public
static
int
queryBookAmount
(
Book
book
)
{
PreparedStatement
preparedStatement
=
null
;
ResultSet
resultSet
=
null
;
int
price
=
0
;
try
{
String
sql
=
"select price from book where id=? "
;
preparedStatement
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
preparedStatement
.
setLong
(
1
,
book
.
getId
());
resultSet
=
preparedStatement
.
executeQuery
();
if
(
resultSet
.
next
())
{
price
=
resultSet
.
getInt
(
"price"
);
}
if
(
resultSet
!=
null
)
{
resultSet
.
close
();
}
if
(
preparedStatement
!=
null
)
{
preparedStatement
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
price
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/won/query/BorrowRecordQuery.java
+
13
-
15
View file @
3767b161
...
...
@@ -25,13 +25,13 @@ public class BorrowRecordQuery {
try
{
switch
(
queryMode
)
{
case
ById:
sql
=
"update book set surplus=surplus-1
and
id=?"
;
sql
=
"update book set surplus=surplus-1
where
id=?"
;
preparedStatement
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
preparedStatement
.
setLong
(
1
,
book
.
getId
());
preparedStatement
.
executeUpdate
();
break
;
case
ByBookname:
sql
=
"update book set surplus=surplus-1
and
bookname=?"
;
sql
=
"update book set surplus=surplus-1
where
bookname=?"
;
preparedStatement
=
DBConnect
.
getConnect
().
prepareStatement
(
sql
);
preparedStatement
.
setString
(
1
,
book
.
getBookname
());
preparedStatement
.
executeUpdate
();
...
...
@@ -42,7 +42,6 @@ public class BorrowRecordQuery {
}
}
public
static
void
updateBorrowRecord
(
BorrowRecord
borrowRecord
)
{
Connection
connection
=
DBConnect
.
getConnect
();
try
{
...
...
@@ -89,34 +88,34 @@ public class BorrowRecordQuery {
}
}
public
static
List
<
BorrowRecord
>
queryBorrowRecord
ByUserId
(
long
userId
)
{
public
static
List
<
BorrowRecord
>
query
All
BorrowRecord
()
{
Connection
connection
=
DBConnect
.
getConnect
();
ResultSet
resultSet
=
null
;
try
{
PreparedStatement
preparedStatement
=
null
;
String
sql
=
"select * from borrowrecord where userid=?"
;
preparedStatement
=
connection
.
prepareStatement
(
sql
);
preparedStatement
.
setLong
(
1
,
userId
);
String
sql
=
"select * from borrowrecord"
;
PreparedStatement
preparedStatement
=
connection
.
prepareStatement
(
sql
);
resultSet
=
preparedStatement
.
executeQuery
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
){
out
.
println
(
e
);
}
return
getBorrowRecordByResultSet
(
resultSet
);
}
public
static
List
<
BorrowRecord
>
queryAllBorrowRecord
(){
public
static
List
<
BorrowRecord
>
queryBorrowRecordByUserId
(
long
userId
)
{
Connection
connection
=
DBConnect
.
getConnect
();
ResultSet
resultSet
=
null
;
try
{
String
sql
=
"select * from borrowrecord"
;
PreparedStatement
preparedStatement
=
connection
.
prepareStatement
(
sql
);
PreparedStatement
preparedStatement
=
null
;
String
sql
=
"select * from borrowrecord where userid=?"
;
preparedStatement
=
connection
.
prepareStatement
(
sql
);
preparedStatement
.
setLong
(
1
,
userId
);
resultSet
=
preparedStatement
.
executeQuery
();
}
catch
(
SQLException
e
){
}
catch
(
SQLException
e
)
{
out
.
println
(
e
);
}
return
getBorrowRecordByResultSet
(
resultSet
);
}
public
static
List
<
BorrowRecord
>
getBorrowRecordByResultSet
(
ResultSet
resultSet
)
{
List
<
BorrowRecord
>
borrowRecords
=
new
LinkedList
<>();
if
(
resultSet
==
null
)
{
...
...
@@ -138,7 +137,6 @@ public class BorrowRecordQuery {
return
borrowRecords
;
}
public
static
void
deleteRecordByRecordId
(
long
recordId
)
{
// TODO Auto-generated method stub
out
.
println
(
"正在删除该条记录..."
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help