java大作业,附源码,sqlserver数据库,报告一条龙服务,包你满意
下载链接:点我下载
登入模块功能实现
管理员模块功能介绍
1.查询图书
2.借阅图书
3.归还图书
4.删除图书
5.添加图书
6.删除用户
7.查询用户
用户模块功能介绍
1.查询图书
2.借阅图书
3.归还图书
4.注册
数据库表的设计
1.admin表
2.reader表
3.book表
4.book_information表
部分代码展示
/*
* 登录事件处理
*/
private int adminLogin(ActionEvent e) {
String userName = this.user_name.getText();
String password = new String(this.user_password.getPassword());//获取密码
//从一个类的函数中得到一个成员变量,传输到另一个类中进行使用
QueryBookInterface.setAdminId(userName);
//提示框
if(StringNull.isEmpty(userName)) {
JOptionPane.showMessageDialog(null, "管理员名不能为空!");
return 0;
}
if(StringNull.isEmpty(password)) {
JOptionPane.showMessageDialog(null, "密码不能为空!");
return 0;
}
Admin admin = new Admin(userName,password);
Connection con =null;
try {
con = conutil.loding();//连接数据库
Admin curreatAdmin= adminDao.login(con, admin);
if(curreatAdmin!=null) {
//提示框
JOptionPane.showMessageDialog(null, "管理员登陆成功!");
return 1;
}else {
JOptionPane.showMessageDialog(null, "管理员名或者密码错误!");
return 0;
}
}catch(Exception e1){
e1.printStackTrace();
return 0;
}finally {
try {
conutil.closeCon(con);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
/*
*
*/
private int userLogin(ActionEvent e) {
String userName1 = this.user_name.getText();
String password1 = new String(this.user_password.getPassword());//获取密码
//从一个类的函数中得到一个成员变量,传输到另一个类中进行使用
QueryBookInterface.setReaderId(userName1);
//提示框
if(StringNull.isEmpty(userName1)) {
JOptionPane.showMessageDialog(null, "用户名不能为空!");
return 0;
}
if(StringNull.isEmpty(password1)) {
JOptionPane.showMessageDialog(null, "密码不能为空!");
return 0;
}
Reader reader =new Reader(userName1,password1);
Connection con =null;
try {
con = conutil.loding();//连接数据库
Reader curreatReader= readerDao.login(con, reader);
if(curreatReader!=null) {
//提示框
JOptionPane.showMessageDialog(null, "登陆成功!");
return 1;
}else {
JOptionPane.showMessageDialog(null, "用户名或者密码错误!");
return 0;
}
}catch(Exception e1){
e1.printStackTrace();
return 0;
}finally {
try {
conutil.closeCon(con);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public ResultSet query(Connection con,Book book)throws Exception{
ResultSet resultUser = null;
StringBuffer sql = new StringBuffer("select * from book");
//数据库模糊查询
if(StringNull.isNotEmpty(book.getBook_name())) {
sql.append(" and book_name like '%"+book.getBook_name()+"%'");
}
if(StringNull.isNotEmpty(book.getBook_writer())) {
sql.append(" and book_writer like '%"+book.getBook_writer()+"%'");
}
if(StringNull.isNotEmpty(book.getBook_publish())) {
sql.append(" and book_publish like '%"+book.getBook_publish()+"%'");
}
PreparedStatement pstmt = (PreparedStatement)con.prepareStatement(sql.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
/**
* 查询图书
*/
public ResultSet query2(Connection con,Book book)throws Exception{
ResultSet resultUser = null;
String sql = "select * from book where book_id=?";
PreparedStatement pstmt = (PreparedStatement)con.prepareStatement(sql);
pstmt.setInt(1, book.getBook_id());
return pstmt.executeQuery();
}
/**
* 借书
*/
private void borrowBook() {
String bookId = this.book_RBidTxt.getText();
String bookName = this.book_RBnameTxt.getText();
String bookPublish = this.book_RBpublishTxt.getText();
String bookWriter = this.book_RBwriterTxt.getText();
String bookStatus = this.book_RBstatusTxt.getText();
if(StringNull.isEmpty(bookId)) {
JOptionPane.showMessageDialog(null, "图书信息不能为空!");
return;
}
if(bookStatus.equals("1")) {
JOptionPane.showMessageDialog(null, "该图书已被借走了!");
return;
}
Connection con = null;
try {
con = conutil.loding();
BookInformation bi;
if(StringNull.isNotEmpty(readerName)) {
bi = new BookInformation(Integer.parseInt(bookId), readerName, null, null, "1");//读者
}else {
bi = new BookInformation(Integer.parseInt(bookId), adminName, null, null, "1");//管理员
}
Book book =new Book(Integer.parseInt(bookId), bookName, bookWriter, bookPublish, "1");
int find = bookInformationDao.add(con, bi);
int flag = bookDao.update(con, book);
if(1 != find ||1 != flag) {
JOptionPane.showMessageDialog(null, "借阅失败!");
return;
}else {
JOptionPane.showMessageDialog(null, "借阅成功!");
return;
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "借阅失败!");
return ;
}finally {
try {
conutil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
}
觉得不错的可以前往下载支持一下下
点我下载
来源:oschina
链接:https://my.oschina.net/u/4379065/blog/4358031