图示管理系统(还书、续借、预约功能)jsp+JavaBean+JDBC+servlet+Dao
先在MySql中建一个数据库其中包含三个表,一个book表,一个user表,一个info表
jsp界面只输入图书号,按图书号还书,续借,预约
JavaBean中写了book类,info类,user类,数据库连接类,还有一个时间类
book类
package bean;
public class Book {
private String id;
private String name;
private String author;
private double price;
private String info;
public Book(String id, String name, String author, double price, String info) {
this.id = id;
this.name = name;
this.author = author;
this.price = price;
this.info = info;
}
public Book() {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}
info类
package bean;
public class Info {
private String id;
private String name;
private String uname;
private String type;
private String lendate;
private String huanqi;
private String cq;
private String info;
private String appoint;
public Info() {}
public Info(String id, String name, String uname, String type, String lendate, String huanqi, String cq,
String info, String appoint) {
this.id = id;
this.name = name;
this.uname = uname;
this.type = type;
this.lendate = lendate;
this.huanqi = huanqi;
this.cq = cq;
this.info = info;
this.appoint = appoint;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLendate() {
return lendate;
}
public void setLendate(String lendate) {
this.lendate = lendate;
}
public String getHuanqi() {
return huanqi;
}
public void setHuanqi(String huanqi) {
this.huanqi = huanqi;
}
public String getCq() {
return cq;
}
public void setCq(String cq) {
this.cq = cq;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getAppoint() {
return appoint;
}
public void setAppoint(String appoint) {
this.appoint = appoint;
}
}
user类
package bean;
public class User {
private String uname;
private String password;
private String info;
public User() {}
public User(String uname, String password, String info) {
this.uname = uname;
this.password = password;
this.info = info;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
}
数据库连接类(可作为模板,任何使用JDBC都可以建此类,调用即可)
package bean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class SJKLJ {
private static String driverName="com.mysql.jdbc.Driver";
private static String userName="root";
private static String userPwd="root";
private static String dbName="bookmanage";
public static Connection getDBconnection() {
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=GB2312";
String url=url1+url2+url3;
try {
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);
return conn;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void closeB(Connection conn,PreparedStatement pstmt,ResultSet rs) {
try {
if(rs!=null)rs.close();
if(pstmt!=null) pstmt.close();
if(conn!=null) conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
时间类(其中包含借书,续借,和超期的时间,我只用到了续借)
package bean;
import java.text.SimpleDateFormat;
import java.util.*;
public class Date_d {
private String now;
public String now_time() {
// SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
Calendar calendar = Calendar.getInstance();
int cur_month=calendar.get(Calendar.MONTH)+1;
int cur_year=calendar.get(Calendar.YEAR);
int cur_day=calendar.get(Calendar.DAY_OF_MONTH);
now = cur_year+"-"+cur_month+"-"+cur_day;
return now;
}
public String huanq() {
Calendar calendar = Calendar.getInstance();
int cur_month=calendar.get(Calendar.MONTH)+2;
int cur_year=calendar.get(Calendar.YEAR);
int cur_day=calendar.get(Calendar.DAY_OF_MONTH);
now = cur_year+"-"+cur_month+"-"+cur_day;
return now;
}
public String Xujie() {
Calendar calendar = Calendar.getInstance();
int cur_month=calendar.get(Calendar.MONTH)+3;
int cur_year=calendar.get(Calendar.YEAR);
int cur_day=calendar.get(Calendar.DAY_OF_MONTH);
now = cur_year+"-"+cur_month+"-"+cur_day;
return now;
}
@SuppressWarnings("unused")
public long chaoq(String bl) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//开始时间
Date startDate = sdf.parse(bl);
//结束时间
Date endDate = sdf.parse(this.now_time());///
//得到相差的天数 betweenDate
long betweenDate = (endDate.getTime() - startDate.getTime())/(60*60*24*1000);
return betweenDate;
}
}
servlet类,我只写了查询id,三个功能的servlet是一样的,只是跳转到的jsp名不一样
Dao中写了,查找id,还书时(更新book的info为可借,更新info表的info为已还),续借时(只需将info表的huanqi加一个月即可),预约时(更新book表的info为不可预约,更新info表的appoint的信息为已被预约)
package Dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import bean.Book;
import bean.Date_d;
import bean.Info;
import bean.SJKLJ;
public class Dao {
public List<Info> select(String id) throws Exception{
String sql="select id,name,uname,type,lendate,huanqi,cq,info,appoint from info where id="+id;
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
List<Info> list=new ArrayList<Info>();
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
rs.last();
if(rs.getRow()!=0) {
rs.beforeFirst();
while(rs.next()) {
String id1=rs.getString("id");
String name=rs.getString("name");
String uname=rs.getString("uname");
String type=rs.getString("type");
String lendate=rs.getString("lendate");
String huanqi=rs.getString("huanqi");
String cq=rs.getString("cq");
String info=rs.getString("info");
String appoint=rs.getString("appoint");
Info in=new Info(id1,name,uname,type,lendate,huanqi,cq,info,appoint);
list.add(in);
}
}
SJKLJ.closeB(conn, pstmt, rs);
return list;
}
public int update_b(String id) throws Exception{
String sql="update book set info = '可借' where id = "+id;
Connection conn=null;
PreparedStatement pstmt=null;
int n=0;
@SuppressWarnings("unused")
String m=null;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
n=pstmt.executeUpdate();
SJKLJ.closeB(conn, pstmt, null);
return n;
}
public int update_i(String id) throws Exception{
String sql="update info set info ='已还' where id ="+id;
Connection conn=null;
PreparedStatement pstmt=null;
int n=0;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
n=pstmt.executeUpdate() ;
SJKLJ.closeB(conn, pstmt, null);
return n;
}
public int update_in(String id)throws Exception{
Date_d dd=new Date_d();
String now=dd.Xujie();
String sql="update info set huanqi='"+now+"' where id="+id;
Connection conn=null;
PreparedStatement pstmt=null;
int n=0;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
n=pstmt.executeUpdate() ;
SJKLJ.closeB(conn, pstmt, null);
return n;
}
public int update_bo(String id)throws Exception{
String sql="update book set info='不可预约' where id="+id;
Connection conn=null;
PreparedStatement pstmt=null;
int n=0;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
n=pstmt.executeUpdate() ;
SJKLJ.closeB(conn, pstmt, null);
return n;
}
public int update_inf(String id)throws Exception{
String sql="update info set appoint='已被预约' where id="+id;
Connection conn=null;
PreparedStatement pstmt=null;
int n=0;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
n=pstmt.executeUpdate() ;
SJKLJ.closeB(conn, pstmt, null);
return n;
}
public List<Book> select_b(String id)throws Exception{
String sql="select id,name,author,price,info from book where id="+id;
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
conn=SJKLJ.getDBconnection();
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
rs.last();
List<Book> list=new ArrayList<Book>();
if(rs.getRow()!=0) {
rs.beforeFirst();
while(rs.next()) {
String id1=rs.getString("id");
String name=rs.getString("name");
String author=rs.getString("author");
Double price=rs.getDouble("price");
String info=rs.getString("info");
Book bb=new Book(id1,name,author,price,info);
list.add(bb);
}
}
SJKLJ.closeB(conn, pstmt, null);
return list;
}
}
最后的show.jsp中,还书和预约相似,续借更为简单
还书:
<%@ page language="java" import="bean.*" import="java.util.*" import="Dao.Dao"
import="java.sql.*" import="bean.SJKLJ" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Dao d=new Dao();
//System.out.println("111");
@SuppressWarnings("unchecked")
List<Info> list=(List<Info>)session.getAttribute("list");
if(list.get(0).getInfo().equals("")){
//System.out.println("444");
//System.out.println(list.get(0).getId());
int nn=d.update_i(list.get(0).getId());
//System.out.println("222");
if(nn==1){
int mm=d.update_b(list.get(0).getId());
if(mm==1){
%>还书成功!<%
}else{
%>还书失败,出现异常错误!<%
}
}
}else{
%>您已经还过此书!<%
}
%>
</body>
</html>
续借:
<%@ page language="java" import="bean.*" import="Dao.Dao" import="java.util.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Dao d=new Dao();
System.out.println("222");
@SuppressWarnings("unchecked")
List<Info> list=(List<Info>)session.getAttribute("list");
System.out.println("333");
int m=d.update_in(list.get(0).getId());
System.out.println("444");
if(m==1){
System.out.println("555");
//Date_d dd=new Date_d();
//String hq=dd.huanq();
%>续借成功!续借时间为30天,请按时还书!<%
}else{
%>续借失败!<%
}
%>
</body>
</html>
预约:
<%@ page language="java" import="bean.*" import="java.util.*" import="Dao.Dao"
import="java.sql.*" import="bean.SJKLJ" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Dao d=new Dao();
@SuppressWarnings("unchecked")
List<Book> list=(List<Book>)session.getAttribute("list");
if(list.get(0).getInfo().equals("预约")){
//System.out.println("444");
//System.out.println(list.get(0).getId());
int nn=d.update_inf(list.get(0).getId());
//System.out.println("222");
if(nn==1){
%>预约成功!<%
}else{
%>出现异常错误!<%
}
}else{
%>预约失败!<%
}
%>
</body>
</html>
想要添加其他的功能只需在Dao里添加即可!
图示管理系统(还书、续借、预约功能)jsp+JavaBean+JDBC+servlet+Dao相关推荐
- 实验五 实现购物车功能(jsp+javabean+jdbc+mysql数据库)
我把该实验的源码和数据库上传到了资源里,你们要的直接点击链接下载就行,如果链接被吞,麻烦评论我一下,我在再次上传. https://download.csdn.net/download/fenger_ ...
- java jdbc标签jsp_jsp+servlet+javabean+jdbc实现增删改查和分页功能 案例源码
[实例简介] 客户管理案例 1.目的:总结JDBC,和Servlet JSP结合到一起. 2.开发中的一些小技巧. 3.客户管理平台功能 * 添加客户 * 查询所有的客户的信息 * 修改客户信息 * ...
- servlet+javabean+jdbc+mysql基于MVC模式的课件管理系统,有三个表的增删改查和课件搜索、课件上传、课件下载功能, 具体功能请看界面上的导航条
源码支持在idea.eclipse.myeclipse运行,数据库采用MySQL数据库,项目采用mvc设计模式开发,页面采用jsp+html+css+js完成. servlet+javabean+jd ...
- java wed登录面 代码_JavaWeb实现用户登录注册功能实例代码(基于Servlet+JSP+JavaBean模式)...
下面通过通过图文并茂的方式给大家介绍JavaWeb实现用户登录注册功能实例代码,一起看看吧. 一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBea ...
- import java.io后报错_用JSP+JAVABEAN实现一个根据圆半径求圆面积、圆周长的功能:为什么我的老出错啊错误:...
用JSP+JAVABEAN实现一个根据圆半径求圆面积.圆周长的功能:为什么我的老出错啊错误: 圆的半径是: 圆的面积是: 圆的周长是: package tools; import java.io.*; ...
- php足疗预约,足浴养生管理系统轻松实现各种线上预约功能?
越来越多的人开始注重养生,不仅是因为工作压力,也是由于人们开始注重自身健康,毕竟革命需要本钱,花钱去做一次足疗.足浴换得身心的短暂修复,成为了许多人的首选,所以传统足疗足浴行业面临新的消费人群,以及消 ...
- jsp和MySQL实现会员卡功能_健身房会员卡管理系统的设计与实现(JSP,MySQL)(含录像)...
健身房会员卡管理系统的设计与实现(JSP,MySQL)(含录像)(论文14000字,程序代码,MySQL数据库) The design and implementation of a gym memb ...
- 基于javaweb的图书管理系统(java+jsp+layui+bootstrap+servlet+mysql)
基于javaweb的图书管理系统(java+jsp+layui+bootstrap+servlet+mysql) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse ...
- MySQL计算机机房管理系统_机房管理系统的设计与实现(JSP,MySQL)(含录像)
机房管理系统的设计与实现(JSP,MySQL)(含录像)(毕业论文7500字,程序代码,MySQL数据库) 为了提高机房管理者的管理效率和减轻管理者的劳动强度,提高机房的利用率,发挥计算机的方便性和快 ...
最新文章
- 【软件工程】5.8 黑盒白盒测试
- pytorch保存模型pth_Pytorch_trick_04
- python中的所有功能_python – 是否可以列出模块中的所有功能?
- react-native-baidu-map使用及注意问题
- linux shell读取配置文件中的内容
- (转)淘淘商城系列——SSM框架整合之Service层整合
- 5.12 操作系统——进程调度
- python爬取歌词_利用Python网络爬虫抓取网易云音乐歌词
- 整理下常用到的css属性
- html访问共享文件夹,教大家如何通过IP地址访问共享文件夹
- MSCS+FailSafe 双机集群做HA 小结
- 商标注册成功后的中肯建议
- 学习中LINUX中常见问题
- 路由2台,二层交换机4台,三层1台,实现网络互联
- 如何删除windows 10系统桌面的所有快捷图标
- Modbus设备通过边缘网关接入阿里云IoT平台
- 小白亲身实践VMware15.0.1Pro彻底卸载
- 网页设计基础教程(1) PS篇
- VC界面程序中文字乱码问题
- 华中科技大学--数据结构课程设计 ---红楼梦人物关系分析
热门文章
- 计算机 网络属性打不开,w10网络设置属性打不开怎么办_win10网络设置属性无法打开如何修复...
- Vczh Library++3.0实现二进制模板函数
- MITRE ATTCK报告发布 FortiEDR连续两年100%拦截恶意攻击
- 以假乱真的AI美女,有着让人羡慕的好身材
- 二、电容屏的工艺流程
- 读书笔记:《德鲁克管理思想精要》- 8 汇总
- 计算机技术在心理学研究应用,面向心理学领域的计算机技术的应用
- Spark: createDataFrame() vs toDF()
- 2018MathorCup D题——公交移动支付问题分析
- Kmeans聚类K值的确定