java项目开发实例图书信息管理系统开发及源码
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;import java.awt。
BorderLayout;import java.awt.Container;import java。
awt.GridLayout;import java。
awt。
event.ActionEvent;import java.awt.event。
ActionListener;import java。
sql.ResultSet;import javax。
swing。
JButton;import javax.swing.JComboBox;import javax。
swing。
JFrame;import javax。
swing.JLabel;import javax.swing。
JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_add extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,address;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField, borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息”);c=getContentPane();c.setLayout(new BorderLayout());book_id_label=new JLabel("编号",JLabel.CENTER);book_name_label=new JLabel(”名称",JLabel.CENTER);author_label=new JLabel(”作者”,JLabel.CENTER);press_label=new JLabel("出版社",JLabel。
Java图书管理系统附源码
Java图书管理系统附源码随着信息化的快速发展,图书馆已成为人们获取知识的重要场所。
为了提高图书馆的管理效率,本文介绍了一个基于Java语言的图书管理系统,并附带了完整的源代码。
该图书管理系统主要包括图书管理、读者管理、借阅管理、系统管理等模块。
系统采用B/S架构,以Java语言开发,运行在Windows平台上。
该系统具有操作简单、界面友好、维护方便等特点。
图书管理模块:实现图书的入库、修改、删除、查询等功能。
图书信息包括书名、作者、社、时间等。
读者管理模块:实现读者的入库、修改、删除、查询等功能。
读者信息包括姓名、性别、出生日期、方式等。
借阅管理模块:实现图书的借阅、归还、续借等功能。
借阅信息包括借书证号、书名、借阅时间、归还时间等。
系统管理模块:实现用户管理、权限管理等。
用户信息包括用户名、密码、角色等。
登录:用户输入用户名和密码,系统验证通过后进入主界面。
添加图书:管理员可以添加图书信息,包括书名、作者、社等。
添加读者:管理员可以添加读者信息,包括姓名、性别、方式等。
借阅图书:读者可以查询图书信息,并申请借阅。
管理员可以审核借阅申请,并决定是否同意。
归还图书:读者可以归还图书,管理员可以查询归还情况。
统计报表:系统可以生成各种报表,如图书借阅排行榜、读者借阅排行榜等。
由于篇幅限制,这里只提供部分源代码,完整源代码请参考附件。
随着信息技术的快速发展,图书馆作为信息和知识的聚集地,其传统的管理方式已经无法满足读者的需求。
为了提高图书管理效率,本文旨在研究基于Java的图书管理系统。
图书管理系统是图书馆的重要组成部分,它可以帮助图书馆工作人员和读者更加方便地管理图书资源。
传统的图书管理系统往往采用人工方式进行管理,这种方式不仅效率低下,而且容易出错。
因此,研究一种基于Java的图书管理系统势在必行。
基于Java的图书管理系统采用B/S架构,即浏览器与服务器之间的架构。
该架构将系统的业务逻辑和数据存储交由服务器处理,客户端通过浏览器访问系统。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码import .*;import .*;public class T{public static void main(String[] args) throws Exception{Connection conn=null;Statement stmt=null;ResultSet rs=null;while(true){Scanner scanner=new Scanner;"请输入用户名:");String username2=();"请输入密码:");String password2=();if(!("")||(""))){try{("");conn=("jdbc:odbc:book","","");String sql="select * from ww where username='"+username2+"'";stmt=();rs=(sql);if()){if("password").equals(password2)){"***欢迎来山东科技大学图书馆管理系统**");while(true){" 1.图书信息");" 2.读者信息");" 3.管理员信息");" 4.借阅信息");" 5.还书信息");" 6.逾期罚款或损坏赔偿信息");出");" 请输入选择功能的序号:");int a=();switch(a){case 1:" 图书信息: ");" 1. 查询图书信息: ");" 2. 插入图书信息: ");" 3. 删除图书信息: ");" 4. 修改图书信息: ");int a1=();switch(a1){case 1:" 欢迎进入图书信息查询系统: ");" 1. 无条件查询图书信息: ");" 2. 条件查询图书信息: ");int d=();switch(d){case 1:int llll=0;无条件查询图书信息: ");String Sql0 = "SELECT * FROM systembook ";rs= (Sql0);while()){String bookID =(1);String bookNo =(2);String bookName =(3);String bookWriter =(4);String bookPub =(5);","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}"是否继续插入yes/no no返回主菜单");String k=();if("yes"))};if("no")){llll=1;};}break;条件查询图书信息: ");" 1. 单条件查询图书信息: ");" 2. 模糊条件查询图书信息: ");" 3. 多表连接查询图书信息: ");" 4. 嵌套查询图书信息: ");" 5. 谓词演算查询");int c12=();switch(c12){case 1:" 1.单条件查询: ");" 1.按图书名编码号查询图书信息: ");int ddd=0;while(ddd!=1){"请输入图书编码号:");String A=();String sql1= "SELECT * FROM systembook WHERE bookID ='"+A+"' ";rs= (sql1);int x=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);x++;}if(x==0){"查无此书,请重新输入");else{"是否继续按姓名查询yes/no no返回主菜单");String k=();if("yes")){};if("no")){ddd=1;};};}break;case 2:" 2.模糊查询图书信息: ");int dc=0;while(dc!=1){"请用户输入图书名字中的模糊关键字");String E=();String sq123= "SELECT * FROM systembook WHERE bookName LIKE'"+E+"%'";rs= (sq123);int z=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);z++;}if(z==0){"查无此书,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no 返回主菜单");String k=();if("yes")){};if("no")){dc=1;表连接查询查询图书信息: ");int dq=0;while(dq!=1){"查询逾期罚款或是赔偿表中的读者的相关信息");"请输入逾期罚款或是赔偿的读者编码号");String F=();String sq1234= "SELECT * FROM fine,borrowbook,systemreader WHERE = AND = AND ='"+F+"' ";rs= (sq1234);int n=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);n++;}if(n==0){"查无此人,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no返回主菜单");if("yes")){};if("no")){ddd=1;};}}break;case 4:" 4.嵌套查询图书信息: ");int dq1=0;while(dq1!=1){"查询某读者所在年级女读者的相关信息");"请输入某读者的读者编号");String G=();String sq12345= "SELECT * FROM systemreader WHERE reaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";rs= (sq12345);int m=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);m++;}if(m==0){"查无此书,请重新输入");}else{"是否继续输入读者编号yes/no no返回主菜单");if("yes")){};if("no")){d=1;};}}break;case 5:" 5. 谓词演算查询:");int dq1123=0;while(dq1123!=1){"查询借阅了某本书的读者的相关信息");"请输入该书的名字");String H=();String sq123456= "SELECT * FROM systemreader WHERE reaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";rs= (sq123456);int l=0;while()){String a2 =(1);String b2 =(2);String c2 =(3);String d2 =(4);String e2 =(5);","+b2+" ,"+c2+","+d2+","+e2);l++;}if(l==0){"查无此人,请重新输入");}else{"是否继续输入图书名字yes/no no返回主菜单");String k=();if("yes")){} ;if("no")){d=1;};}}break;}查询图书信息: ");String Sql = "SELECT * FROM systembook ";rs= (Sql);while()){插入图书信息: ");"请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String insertSql="INSERT INTO systembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";int i=(insertSql); 删除图书信息: ");"请输入要删除的图书编号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM systembook where bookID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){"没有这本书,请重新输入");}else{{String deleSql= "DELETE FROM systembook WHERE bookID='"+b3+"'";int p=(deleSql); 修改图书信息: ");"请输入修改的图书ID ");String S=();String sql1="SELECT * FROM systembook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);String e222 =(5);String f222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){"没有这本书,请重新输入");}else{"要将书名改为");String bbb=();String updateSql1="UPDATE systembook SET bookName='"+bbb+"' WHERE bookID='"+S+"'";int hh=(updateSql1); 查询读者信息: ");" 2. 插入读者信息: ");" 3. 删除读者信息: ");" 4. 修改读者信息: " );int b1=();switch(b1){case 1:" 1. 查询读者信息: ");String ssql = "SELECT * FROM systemreader ";rs= (ssql);while()){插入读者信息: ");"请按顺序插入借书卡证号读者名字读者学号读者性别读者LBID 读者类型读者学院读者年级读者专业办证日期");String str=();String []splitst=(",");String b11=splitst[0];String b12=splitst[1];String b13=splitst[2];String b14=splitst[3];String b15=splitst[4];String b16=splitst[5];String b17=splitst[6];String b18=splitst[7];String b19=splitst[8];String b20=splitst[9];String insertSql="INSERT INTO systemreader(reaID,reaName,reaNo,reaSex,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate) VALUES('"+b11+"','"+b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','"+b19+"' ,'"+b20+"')";int n=(insertSql); 删除读者信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String r=Splitst[0];String sql1="SELECT * FROM systemreader where reaID='"+r+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);String g22 =(7);String h22 =(8);String i22 =(9);","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22);kkk++;}if(kkk==0){"没有这个读者,请重新输入");}else{修改读者信息: ");"请输入修改以后的读者的ID ");String S=();查询管理员信息: ");" 2. 插入管理员信息: ");" 3. 删除管理员信息: ");" 4. 修改管理员信息: ");" 5. 返回上一级");int c11=();switch(c11){case 1:" 1. 查询管理员信息: ");String Ssql = "SELECT * FROM manager ";rs= (Ssql);while()){插入管理员信息: ");"请按顺序插入管理员的编号,管理员的姓名,管理员的性别,所管书库,电话,地址");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String a16=splitst[5];String insertSql="INSERT INTO manager(mID,mName,mSex,mAuth,mTeleph,mAddre)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+"')";int i=(insertSql); 删除管理员信息: ");"请输入要删除的管理员编号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM manager where mID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);String e22 =(5);String f22 =(6);","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){"没有这个管理员,请重新输入");}else{修改管理员信息: ");"请输入要修改的管理员编号:");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String sql1="SELECT * FROM manager where mID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);String e222 =(5);String f222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){"没有这个管理员,请重新输入");}else{查询图书借阅信息信息: ");" 2. 插入图书借阅信息: ");" 3. 删除图书借阅信息: ");" 4. 修改图书借阅信息: ");" 5. 返回上一级");int d=();switch(d){case 1:" 1. 查询图书借阅信息: ");String Sql4 = "SELECT * FROM borrowbook ";rs= (Sql4);while()){String bookID =(1);String reaID =(2);String outDate =(3);String yhDate =(4);","+reaID+","+outDate+","+yhDate);}break;case 2:int zz=0;while(zz!=1){" 2. 插入图书借阅信息: ");"请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];删除图书借阅信息: ");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";rs= (sql1);int kkk=0;while()){String a22 =(1);String b22 =(2);String c22 =(3);String d22 =(4);修改借阅读书信息: ");"请输入要修改的图书的ID ");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){String a222 =(1);String b222 =(2);String c222 =(3);String d222 =(4);查询还书信息: ");" 2. 插入还书信息: ");" 3. 删除还书信息: ");" 4. 修改还书信息: ");" 5. 返回上一级");int e=();switch(e){case 1:" 1. 查询还书信息: ");sql = "SELECT * FROM return ";rs= (sql);while()){String reaID =(1);String bookID =(2);String bookName =(3);String inDate =(4);","+bookID+","+bookName+","+ inDate);}break;case 2:" 2. 插入还书信息: ");"请按顺序插入读者卡号,图书编号,图书名称,还书日期");String str=();String []splitst=(",");String e1=splitst[0];String e2=splitst[1];String e3=splitst[2];String e4=splitst[3];String insertSql="INSERT INTO returnbook(reaID,bookID,bookName,inDate) VALUES('"+e1+"','"+e2+"','"+e3+"','"+e4+"')";int h=(insertSql); 删除还书书信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String f3=Splitst[0];String deleSql= "DELETE FROM return WHERE reaID='"+f3+"'";int w=(deleSql); 查询罚款信息: ");" 2. 插入罚款信息: ");" 3. 删除罚款信息: ");" 4. 修改罚款信息: ");int g=();switch(g){case 1:" 1. 查询罚款信息: ");String Sssql = "SELECT * FROM fine ";rs= (Sssql);while()){插入罚款信息: ");"请按顺序插入读者卡号,图书编号,借书日期,超出日期,应缴罚款");String str=();String []splitst=(",");String g1=splitst[0];String g2=splitst[1];String g3=splitst[2];String g4=splitst[3];String g5=splitst[4];删除罚款信息: ");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");String r=Splitst[0];String deleSql= "DELETE FROM fine WHERE reaID='"+r+"'";int x=(deleSql); 查询借阅历史信息: ");" 2. 插入借阅历史信息: ");" 3. 删除借阅历史信息: ");" 4. 修改借阅历史信息: ");" 5. 返回上一级");int h=();switch(h){" 1. 查询历史借阅信息: ");String Sql7 = "SELECT * FROM borrowhistory ";rs= (Sql7);while()){String bookID =(1);String reaID =(2);String bookName=(3);String bookWriter=(4);String outDate =(5);String yhDate =(6);","+reaID+","+bookName+","+bookWriter+","+outDate+","+yhDate);}break;case 2:" 2. 插入图书历史借阅信息: ");"请按顺序插入图书的的编号,读者编号,,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];删除图书历史借阅信息: ");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String d3=Splitst[0];String deleSql= "DELETE bookID FROM borrowhistory WHERE bookID='"+d3+"'";int k=(deleSql); 修改图书借阅历史信息: ");"请输入要修改的图书的借出日期");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String updateSql="UPDATE borrow SET outDate='"+c1+"' WHERE bookName='数据库'";int t=(updateSql); //返回记录影响的条数if(t!=0){"修改成功!");}break;}}}}}else{"非法用户!");}}catch(SQLException e) {();}//();();();}}}}。
(完整word版)图书管理系统源代码
图书管理系统源代码(一)程序代码1。
主窗口界面import java.awt。
*;import java.awt。
event.*;import javax。
swing.*;import javax.swing.border.TitledBorder;import java.awt。
Font;import javax.swing。
JMenu;public class MainWindow extends JFrame implements ActionListener { private static final long serialVersionUID = 1L;static String loginName;static String loginNo;JLabel mlabel;JPanel jp=new JPanel();//建立菜单栏JMenu a=new JMenu();JMenu b=new JMenu();JMenu c=new JMenu();//建立系统管理菜单组JMenuItem aa=new JMenuItem();JMenuItem ab=new JMenuItem();JMenuItem ac=new JMenuItem();//建立读者管理菜单组JMenuItem bb=new JMenuItem();//建立书籍管理菜单组JMenuItem ca=new JMenuItem();JMenuItem cb=new JMenuItem();JMenuItem cc=new JMenuItem();JMenuItem cd=new JMenuItem();public MainWindow(){super(”图书管理系统");addWindowListener(new WindowAdapter(){System.exit(0);}});Container d=getContentPane();this。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码import .*;import .*;public class T{public static void main(String[] args) throws Exception{Connection conn=null;Statement stmt=null;ResultSet rs=null;*while(true){Scanner scanner=new Scanner;"请输入用户名:");String username2=();"请输入密码:");String password2=();if(!("")||(""))){try{;("");conn=("jdbc:odbc:book","","");String sql="select * from ww where username='"+username2+"'";rs=(sql);if()){if("password").equals(password2)),{"*********欢迎来山东科技大学图书馆管理系统********");while(true){"1.图书信息");"2.读者信息");"3.管理员信息");"4.借阅信息");"5.还书信息");"6.逾期罚款或损坏赔偿信息");出");"请输入选择功能的序号:");int a=();switch(a){case 1:"图书信息:");>"1.查询图书信息:");"2.插入图书信息:");"3.删除图书信息:");"4.修改图书信息:");int a1=();{case 1:)"欢迎进入图书信息查询系统:");"1.无条件查询图书信息:");"2.条件查询图书信息:");int d=();switch(d){case 1:int llll=0;条件查询图书信息:");String Sql0 = "SELECT * FROM systembook ";rs= (Sql0);while()){StringbookID =(1);StringbookNo =(2);String bookName =(3);String bookWriter =(4);!String bookPub =(5);","+bookNo+","+bookName+","+bookWriter+","+bookPub);}"是否继续插入yes/no no返回主菜单");String k=();if("yes")){"no"))='"+A+"' ";{llll=1;2:"2.条件查询图书信息:");"1.单条件查询图书信息:");"2.模糊条件查询图书信息:");"3.多表连接查询图书信息:");"4.嵌套查询图书信息:");"5.谓词演算查询");int c12=();<switch(c12){case 1:"1.单条件查询:");"1.按图书名编码号查询图书信息:");int ddd=0;while(ddd!=1){"请输入图书编码号:");String A=();Stringsql1="SELECT*FROMsystembookWHEREbookIDrs= (sql1); ]int x=0;while()){Stringa2 =(1);Stringb2 =(2);Stringc2 =(3);Stringd2 =(4);Stringe2 =(5);)","+b2+" ,"+c2+","+d2+","+e2);x++;}if(x==0){"查无此书,请重新输入");回主菜单");LIKE'"+E+"%'";}else{"是否继续按姓名查询yes/nono返String k=();、if("yes")){"no")){ddd=1;)};};}break;case 2:"2.模糊查询图书信息:");int dc=0;while(dc!=1){"请用户输入图书名字中的模糊关键字");String E=();;String sq123= "SELECT * FROM systembook WHERE bookNamers= (sq123);int z=0;while()){Stringa2 =(1);Stringb2 =(2);Stringc2 =(3);Stringd2 =(4);、Stringe2 =(5);","+b2+" ,"+c2+","+d2+","+e2);z++;}if(z==0){"查无此书,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no返回主菜单"); )String k=();if("yes")){"no")){dc=1;}break;};}}break;case 3:"3.多表连接查询查询图书信息:");#int dq=0;while(dq!=1){"查询逾期罚款或是赔偿表中的读者的相关信息");"请输入逾期罚款或是赔偿的读者编码号");String F=();String sq1234= "SELECT * FROM fine,borrowbook,='"+F+"' ";rs= (sq1234);int n=0;(while()){Stringa2 =(1);Stringb2 =(2);Stringc2 =(3);Stringd2 =(4);Stringe2 =(5);","+b2+" ,"+c2+","+d2+","+e2);n++;:}if(n==0){"查无此人,请重新输入");}else{"是否继续输入图书名字中的模糊关键字yes/no no返回主菜单");String k=();,if("yes")){"no")){ddd=1;【};}}break;case 4:"4.嵌套查询图书信息:");int dq1=0;while(dq1!=1){("查询某读者所在年级女读者的相关信息");"请输入某读者的读者编号");String G=();Stringsq12345="SELECT*FROMsystemreaderWHEREreaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";rs= (sq12345);int m=0;while())返回主菜单");{Stringa2 =(1);Stringb2 =(2);、Stringc2 =(3);Stringd2 =(4);Stringe2 =(5);","+b2+" ,"+c2+","+d2+","+e2);m++;}if(m==0){"查无此书,请重新输入");})else{"是否继续输入读者编号yes/nonoString k=();if("yes")){"no"))¥{d=1;5:%"5.谓词演算查询:");int dq1123=0;while(dq1123!=1){"查询借阅了某本书的读者的相关信息");"请输入该书的名字");String H=();Stringsq123456="SELECT*FROMsystemreaderWHEREreaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";rs= (sq123456);《int l=0;while()){Stringa2 =(1);Stringb2 =(2);Stringc2 =(3);Stringd2 =(4);Stringe2 =(5);》","+b2+" ,"+c2+","+d2+","+e2);l++;}if(l==0){"查无此人,请重新输入");}else{;"是否继续输入图书名字yes/no no返回主菜单");String k=();if("yes")){"no")){<d=1;1:"1.查询图书信息:");String Sql = "SELECT * FROM systembook";rs= (Sql);while()){入图书信息:");"请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");String str=();String []splitst=(",");String a11=splitst[0];>String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];StringinsertSql="INSERTsystembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";int i=(insertSql); 除图书信息:");"请输入要删除的图书编号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM systembook where bookID='"+b3+"'";rs= (sql1);int kkk=0;;while()){Stringa22 =(1);Stringb22 =(2);Stringc22 =(3);Stringd22 =(4);Stringe22 =(5);Stringf22 =(6);…","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){"没有这本书,请重新输入");}else{%{StringdeleSql="DELETEFROMsystembookWHEREbookID='"+b3+"'";int p=(deleSql); 改图书信息:");"请输入修改的图书ID");(String S=();String sql1="SELECT * FROM systembook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){Stringa222 =(1);Stringb222 =(2);Stringc222 =(3);]Stringd222 =(4);Stringe222 =(5);Stringf222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){:"没有这本书,请重新输入");}else{"要将书名改为");String bbb=();String updateSql1="UPDATE systembookSET bookName='"+bbb+"'WHERE bookID='"+S+"'";int hh=(updateSql1); 询读者信息:");"2.插入读者信息:");"3.删除读者信息:");"4.修改读者信息:");int b1=();switch(b1){case 1:"1.查询读者信息:");]String ssql = "SELECT * FROM systemreader ";rs= (ssql);while()){入读者信息:");"请按顺序插入借书卡证号读者名字读者学号读者性别读者LBID读者类型读者学院读者年级读者专业办证日期");String str=();String []splitst=(",");String b11=splitst[0];String b12=splitst[1];String b13=splitst[2];String b14=splitst[3];String b15=splitst[4];String b16=splitst[5];String b17=splitst[6];String b18=splitst[7];`String b19=splitst[8];String b20=splitst[9];StringinsertSql="INSERTINTOsystemreader(reaID,reaName,reaNo,reaSe x,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate)VALUES('"+b11+"','"+ b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','" +b19+"','"+b20+"')";int n=(insertSql); 除读者信息:");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");·String r=Splitst[0];String sql1="SELECT * FROM systemreader where reaID='"+r+"'";rs= (sql1);int kkk=0;while()){Stringa22 =(1);Stringb22 =(2);Stringc22 =(3);、Stringd22 =(4);Stringe22 =(5);Stringf22 =(6);Stringg22 =(7);Stringh22 =(8);Stringi22 =(9);","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22) ;kkk++;^}if(kkk==0){"没有这个读者,请重新输入");}else{改读者信息:");"请输入修改以后的读者的ID ");String S=();询管理员信息:");·"2.插入管理员信息:");"3.删除管理员信息:");"4.修改管理员信息:");"5.返回上一级");int c11=();switch(c11){case 1:"1.查询管理员信息:");)String Ssql = "SELECT * FROM manager ";rs= (Ssql);while()){入管理员信息:");"请按顺序插入管理员的编号,管理员的姓名,管理员的性别,所管书库,电话,地址");String str=();.String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String a16=splitst[5];StringinsertSql="INSERT)manager(mID,mName,mSex,mAuth,mTeleph,mAddre)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+" ')";int i=(insertSql); 除管理员信息:");"请输入要删除的管理员编号:");String Str=();String []Splitst=(",");…String b3=Splitst[0];String sql1="SELECT * FROM manager where mID='"+b3+"'";rs= (sql1);int kkk=0;while()){Stringa22 =(1);Stringb22 =(2);!Stringc22 =(3);Stringd22 =(4);Stringe22 =(5);Stringf22 =(6);","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0)|{"没有这个管理员,请重新输入");}else{改管理员信息:");#"请输入要修改的管理员编号:");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String sql1="SELECT * FROM manager where mID='"+S+"'";rs= (sql1);int lll=0;while())~{Stringa222 =(1);Stringb222 =(2);Stringc222 =(3);Stringd222 =(4);Stringe222 =(5);Stringf222 =(6);","+b222+" ,"+c222+","+d222+","+e222+","+f222);、lll++;}if(lll==0){mID='"+S+"'";"没有这个管理员,请重新输入");}else{询图书借阅信息信息:");"2.插入图书借阅信息:");"3.删除图书借阅信息:");—"4.修改图书借阅信息:");"5.返回上一级");int d=();switch(d){case 1:"1.查询图书借阅信息:");String Sql4 = "SELECT * FROM borrowbook ";rs= (Sql4);《while()){String bookID =(1);String reaID =(2);String outDate =(3);String yhDate =(4);","+reaID+","+outDate+","+yhDate);}break;~case 2:int zz=0;while(zz!=1){"2.插入图书借阅信息:");"请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];`String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];除图书借阅信息:");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String b3=Splitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";rs= (sql1);*int kkk=0;while()){Stringa22 =(1);Stringb22 =(2);Stringc22 =(3);Stringd22 =(4);改借阅读书信息:");"请输入要修改的图书的ID ");String S=();String []Ssplitst=(",");;String c1=Ssplitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";rs= (sql1);int lll=0;while()){Stringa222 =(1);Stringb222 =(2);¥Stringc222 =(3);Stringd222 =(4);*/case 5:"还书信息:");"1.查询还书信息:");"2.插入还书信息:");"3.删除还书信息:");"4.修改还书信息:");"5.返回上一级");!int e=();switch(e){case 1:"1.查询还书信息:");sql = "SELECT * FROM return ";rs= (sql);while()){StringreaID =(1);…StringbookID =(2);String bookName =(3);String inDate =(4);","+bookID+","+bookName+","+ inDate);}break;case 2:"2.插入还书信息:");~"请按顺序插入读者卡号,图书编号,图书名称,还书日期");String str=();String []splitst=(",");String e1=splitst[0];String e2=splitst[1];String e3=splitst[2];String e4=splitst[3];StringinsertSql="INSERTINTOreturnbook(reaID,bookID,bookName,inDat e) VALUES('"+e1+"','"+e2+"','"+e3+"','"+e4+"')";(int h=(insertSql); 除还书书信息:");"请输入要删除的读者证号:");String Str=();String []Splitst=(",");:String f3=Splitst[0];String deleSql= "DELETEFROM return WHERE reaID='"+f3+"'";intw=(deleSql); 询罚款信息:");\"2.插入罚款信息:");"3.删除罚款信息:");"4.修改罚款信息:");int g=();switch(g){case 1:"1.查询罚款信息:");String Sssql = "SELECT * FROM fine ";rs= (Sssql);:while()){入罚款信息:");"请按顺序插入读者卡号,号,借书日期,超出日期,应缴罚款");String str=();String []splitst=(",");String g1=splitst[0];String g2=splitst[1];String g3=splitst[2];String g4=splitst[3];String g5=splitst[4];除罚款信息:"请输入要删除的读者证String Str=();String []Splitst=(",");String r=Splitst[0];StringdeleSql="DELETEFROMfineWHEREintx=(deleSql);询借阅历史信息:");"2.插入借阅历史信息:");"3.删除借阅历史信息:");"4.修改借阅历史信息:");"5.返回上一级");int h=();switch(h){case 1:"1.查询历史借阅信息:");String Sql7 = "SELECT * FROM borrowhistory ";rs= (Sql7);while()){String bookID =(1);String reaID =(2);String bookName=(3);String bookWriter=(4);String outDate =(5);String yhDate =(6);","+reaID+","+bookName+","+bookWriter+","+outDate+","+yhDate); }break;case 2:"2.插入图书历史借阅信息:");"请按顺序插入图书的的编号,读者编号,,图书借出日期,图书归还日期");String str=();String []splitst=(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];除图书历史借阅信息:");"请输入要删除的图书条码号:");String Str=();String []Splitst=(",");String d3=Splitst[0];StringdeleSql="DELETEbookIDFROMborrowhistorybookID='"+d3+"'";int k=(deleSql); 改图书借阅历史信息:");"请输入要修改的图书的借出日期");String S=();String []Ssplitst=(",");String c1=Ssplitst[0];String updateSql="UPDATE borrow SET outDate='"+c1+"' WHERE bookName='数据库'";int t=(updateSql); //返回记录影响的条数if(t!=0){"修改成功!");}break;}}}}}else{"非法用户!");}}catch(SQLException e) { ();}//();();();}}}}。
基于java的图书管理系统源代码
import javax.swi ng.J BUtt on;
import javax.sw in g.JComboBox;
import javax.sw in g.JFrame;
import javax.sw in g.JLabel;
import javax.swi ng.J Optio nPane;
Pan eI1.add(book_ nu m_label);
Pan eI1.add(book_ num _TeXtField);
Pan eI1.add(borrowed_ nu m_label);
Pan eI1.add(borrowed_c oun t);
Pan eI1.add(address);
Pan eI1.add(addresst);
ReSUItSet rs;
JPa nel Pan el1,pa nel2;
JLabeI book_id_Iabel,book_ name_label,author_label,
PreSS_label,press_date_label,price_label,book_ num _label,borrowed _num _label,a ddress;
Pan eI2=new JPa nel();
Pan eI2.setLayout (new GridLayout(1,3));
PriCe_label=new JLabeI(价格",JLabel.CENTER); book_num_label=new JLabel("库存数",JLabel.CENTER); borrowed_num」abel=new JLabel("已借阅数",JLabel.CENTER); address=new JLabeI(藏书地址",JLabel.CENTER);
用Java写一个图书管理系统的代码
用Java写一个图书管理系统的代码```import java.util.*;public class BookManager {// Create a list for book storageprivate List<Book> books;public BookManager() {books = new ArrayList<Book>();}// Add a book to the listpublic void addBook(Book book) {books.add(book);}// Remove a book from the listpublic void removeBook(Book book) {books.remove(book);}// Get all books in the listpublic List<Book> getAllBooks() {return books;}// Search a book by book namepublic List<Book> searchByName(String name) {List<Book> resultBooks = new ArrayList<Book>();for (Book book : books) {if (book.getName().equals(name)) {resultBooks.add(book);}}return resultBooks;}// Search a book by author namepublic List<Book> searchByAuthor(String author) { List<Book> resultBooks = new ArrayList<Book>(); for (Book book : books) {if (book.getAuthor().equals(author)) {resultBooks.add(book);}}return resultBooks;}}class Book {private String name;private String author;public Book(String name, String author) { = name;this.author = author;}public String getName() {return name;}public void setName(String name) { = name;}public String getAuthor() {return author;}public void setAuthor(String author) { this.author = author;}}```。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码packagelibrary;publicclassbook_addextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2;JLabelbook_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,address;JTextFieldbook_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBoxaddresst;Containerc;JButtonclear,add,exit;publicbook_add(){super("添加图书信息");c=getContentPane();c.setLayout(newBorderLayout());book_id_label=newJLabel("编号",JLabel.CENTER);book_name_label=newJLabel("名称",JLabel.CENTER);author_label=newJLabel("作者",JLabel.CENTER);press_label=newJLabel("出版社",JLabel.CENTER);press_date_label=newJLabel("出版日期",JLabel.CENTER);price_label=newJLabel("价格",JLabel.CENTER);book_num_label=newJLabel("库存数",JLabel.CENTER);borrowed_num_label=newJLabel("已借阅数",JLabel.CENTER);address=newJLabel("藏书地址",JLabel.CENTER);book_id_TextField=newJTextField(15);book_name_TextField=newJTextField(15);author_TextField=newJTextField(15);press_TextField=newJTextField(15);press_date_TextField=newJTextField(15);price_TextField=newJTextField(15);book_num_TextField=newJTextField(15);borrowed_count=newJTextField(15);borrowed_count.setText("0");addresst=newJComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=newJPanel();panel1.setLayout(newGridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=newJPanel();panel2.setLayout(newGridLayout(1,3));clear=newJButton("清空");clear.addActionListener(this);add=newJButton("添加");add.addActionListener(this);exit=newJButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente) {if(e.getSource()==exit){this.dispose();}elseif(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}elseif(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"书号不能为空");}elseif(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"书名不能为空");}elseif(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"作者不能为空");}elseif(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"出版社不能为空");}elseif(press_date_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"出版日期不能为空");}elseif(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"价格不能为空");}elseif(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"库存不能为空");}elseif(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null,"借阅数不能为空");}else{try{StringstrSQL="insertintobook(book_id,book_name,press,author,press_date,price,book_count,borrow ed_count,store_address) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exceptionex){}}}}}packagelibrary;importjavax.swing.*;importjava.awt.*;publicclassbook_deleteextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JLabelTipLabel=newJLabel("请选择要删除的书名",JLabel.CENTER); JComboBoxbb=newJComboBox();JButtonyes,exit;JPanelpanel1=newJPanel();publicbook_delete(){super("删除图书信息");c=getContentPane();c.setLayout(newBorderLayout());try{StringstrSQL="selectbook_namefrombookwherebook_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=newJButton("确定");exit=newJButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){this.dispose();}elseif(e.getSource()==yes){try{StringstrSQL="selectborrowed_countfrombookwherebook_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{StringstrSql="deletefrombookwherebook_name='"+bb.getSelectedItem()+"'andborrowed_count=0";rs.first();intcount=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}elseif(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;publicclassbook_modifyextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2,panel3;JLabelTipLabel=newJLabel("输入书名点确定,将调出此书的相关信息");JLabelbook_name_label,author_label,press_label,press_date_label,price_label;JTextFieldbook_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Containerc;JButtonclear,yes,update,exit;publicbook_modify(){super("修改图书信息");c=getContentPane();c.setLayout(newBorderLayout());panel3=newJPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=newJLabel("名称",JLabel.CENTER);author_label=newJLabel("作者",JLabel.CENTER);press_label=newJLabel("出版社",JLabel.CENTER);press_date_label=newJLabel("出版日期",JLabel.CENTER);price_label=newJLabel("价格",JLabel.CENTER);book_name_TextField=newJTextField(15);author_TextField=newJTextField(15);press_TextField=newJTextField(15);press_date_TextField=newJTextField(15);price_TextField=newJTextField(15);panel1=newJPanel();panel1.setLayout(newGridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=newJPanel();panel2.setLayout(newGridLayout(1,4));clear=newJButton("清空");yes=newJButton("确定");update=newJButton("更新");exit=newJButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){this.dispose();;}elseif(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}elseif(e.getSource()==yes){try{StringstrSQL="select*frombookwherebook_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerExceptionupe){}catch(Exceptiones){}}elseif(e.getSource()==update){try{StringstrSQL="updatebooksetbook_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"'wherebook_name='"+book_name_TextField.getText().trim()+"'" ;if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else{JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exceptionsqle){}}}}packagelibrary; publicclassbookborrowextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2;JLabelborrowname,bookname,borrowdate,returndate,is_return_label;JTextFieldborrowdateField,returndateField,is_return;JButtonclear,yes,cancel;JComboBoxborrownameBox=newJComboBox();JComboBoxbooknameBox=newJComboBox();publicbookborrow(){super("书籍出借");c=getContentPane();c.setLayout(newBorderLayout());Calendarcal=Calendar.getInstance();intyear,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);//Stringcdate=sdf.format(cal.getTime());//Stringda=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day);borrowname=newJLabel("借阅者姓名",JLabel.CENTER);bookname=newJLabel("书名",JLabel.CENTER);borrowdate=newJLabel("借书日期",JLabel.CENTER);// returndate=newJLabel("应还日期",JLabel.CENTER);is_return_label=newJLabel("是否归还",JLabel.CENTER);borrowdateField=newJTextField(15);// borrowdateField.setText(cdate);// returndateField=newJTextField(15);// returndateField.setText(da);is_return=newJTextField(15);is_return.setText("否");try{StringstrSql="selectstudent_namefromreader";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}try{StringstrSQL="selectbook_namefrombookwherebook_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){}panel1=newJPanel();panel1.setLayout(newGridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=newJPanel();panel2.setLayout(newGridLayout(1,3));clear=newJButton("清空");yes=newJButton("确定");cancel=newJButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==cancel){this.dispose();}elseif(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}elseif(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null,"对不起,没有读者借阅");}elseif(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null,"对不起,现在书库没有书");}else{try{//系统计算归还日期//获取输入的借阅日期,自动加两个月StringstartDate=borrowdateField.getText().trim();SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");DatedateStart=format.parse(startDate);Calendarcd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH,2);StringreturnDate=format.format(cd.getTime());StringstrSQL="insertintoborrow(student_name,book_name,borrow_date,return_date,is_returned)valu es('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"借阅完成");strSQL="updatereadersetborrow_count=borrow_count+1wherestudent_name='"+borrownameBox.ge tSelectedItem()+"'";db.updateSql(strSQL);strSQL="updatebooksetborrowed_count=borrowed_count+1wherebook_name='"+booknameBox.get SelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"借阅失败");db.closeConnection();this.dispose();}}catch(Exceptionse){}}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookborrowlistextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2;JLabelbookname,studentname;JTextFieldbooknamet,studentnamet;JButtonsearch,exit;JTabletable=null;DefaultTableModeldefaultModel=null;publicbookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(newBorderLayout());bookname=newJLabel("书名",JLabel.CENTER);studentname=newJLabel("人名",JLabel.CENTER);booknamet=newJTextField(15);studentnamet=newJTextField(15);search=newJButton("查询");exit=newJButton("退出");search.addActionListener(this);exit.addActionListener(this);Boxbox1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Boxbox2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);BoxboxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=newJPanel();panel1.add(boxH);panel2=newJPanel();String[]name={"读者","书名","借阅时间","应还时间","是否归还"};String[][]data=newString[0][0];defaultModel=newDefaultTableModel(data,name);table=newJTable(defaultModel);table.setPreferredScrollableViewportSize(newDimension(400,80));JScrollPanes=newJScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){db.closeConnection();this.dispose();}elseif(e.getSource()==search){StringstrSQL="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrow";StringstrSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().equals("")){strSql=strSQL;}elseif(studentnamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherebook_ name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherestude nt_name='"+studentnamet.getText().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returnedfromborrowwherestude nt_name='"+studentnamet.getText().trim()+"'andbook_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null,"你借的书还还有7天超期");}try{introwCount=defaultModel.getRowCount()-1;intj=rowCount;for(inti=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){VectorinsertRow=newVector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookborrowModifyextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2,panel3;Containerc;JLabeltiplabel=newJLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabelborrowlabel,namelabel,borrowdate;JTextFieldborrowField,nameField,dateField;JButtonclear,yes,update,cancel;publicbookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(newBorderLayout());panel3=newJPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=newJLabel("借阅者姓名",JLabel.CENTER);namelabel=newJLabel("书名",JLabel.CENTER);borrowdate=newJLabel("借书日期",JLabel.CENTER);borrowField=newJTextField(15);nameField=newJTextField(15);dateField=newJTextField(15);panel1=newJPanel();panel1.setLayout(newGridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=newJPanel();panel2.setLayout(newGridLayout(1,4));clear=newJButton("清空");yes=newJButton("确定");update=newJButton("更新");cancel=newJButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}elseif(e.getSource()==cancel){this.dispose();}elseif(e.getSource()==yes){try{StringstrSQL="selectstudent_name,book_name,borrow_datefromborrowwherestudent_name='"+borrowField.getText().trim()+"'andbook_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exceptionex){}}elseif(e.getSource()==update){StringstrSQL="updateborrowsetborrow_date='"+dateField.getText().trim()+"'wherestudent_name='"+borrowField.getText().trim()+"'andbook_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}packagelibrary;importjavax.swing.*;importjava.awt.*;publicclassbooklistextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;Containerc;JPanelpanel1,panel2,panel3;JLabelbookname,authorname,press;JTextFieldbooknamet,authornamet,presst;JButtonsearch,exit;JTabletable=null;DefaultTableModeldefaultModel=null;publicbooklist(){super("书籍信息查询");c=getContentPane();c.setLayout(newBorderLayout());bookname=newJLabel("书名",JLabel.CENTER);authorname=newJLabel("作者",JLabel.CENTER);press=newJLabel("出版社",JLabel.CENTER);booknamet=newJTextField(15);authornamet=newJTextField(15);presst=newJTextField(15);search=newJButton("查询");exit=newJButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=newJPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=newJPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String[]name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String[][]data=newString[0][0];defaultModel=newDefaultTableModel(data,name);table=newJTable(defaultModel);table.setPreferredScrollableViewportSize(newDimension(400,80));JScrollPanes=newJScrollPane(table);panel3=newJPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==exit){db.closeConnection();this.dispose();}elseif(e.getSource()==search){StringstrSQL="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count, book_count-borrowed_count,store_addressfrombook";StringstrSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")&&presst.getTex t().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherepress='"+presst.getText().trim()+"'";}elseif(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherebook_name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")&&presst.getText().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwhereauthor='"+authornamet.getText().trim()+"'";}else{strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_addressfrombookwherebook_name='"+booknamet.getText().trim()+"'andauthor='"+authornamet.getText().trim()+"'andpress='"+presst.getText().trim()+"'";}try{introwCount=defaultModel.getRowCount()-1;intj=rowCount;for(inti=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){VectorinsertRow=newVector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));insertRow.addElement(rs.getString(6));insertRow.addElement(rs.getString(7));insertRow.addElement(rs.getString(8));insertRow.addElement(rs.getString(9));insertRow.addElement(rs.getString(10));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLExceptionsqle){}catch(Exceptionex){}}}}packagelibrary;importjavax.swing.*;importjava.awt.*; publicclassbookreturnextendsJFrameimplementsActionListener{DataBaseManagerdb=newDataBaseManager();ResultSetrs;JPanelpanel1,panel2;Containerc;JLabelnamelabel,booklabel,returndatelabel;JTextFieldreturnField;JButtonclear,yes,cancel;JComboBoxbookname=newJComboBox();JComboBoxreadername=newJComboBox();publicbookreturn(){super("图书还入");c=getContentPane();c.setLayout(newBorderLayout());Calendarcal=Calendar.getInstance();Stringcdate=sdf.format(cal.getTime());namelabel=newJLabel("还书者姓名",JLabel.CENTER);booklabel=newJLabel("书名",JLabel.CENTER);returndatelabel=newJLabel("日期",JLabel.CENTER);returnField=newJTextField(15);returnField.setText(cdate);try{Strings="";StringstrSQL="selectstudent_namefromreaderwhereborrow_count!=0";rs=db.getResult(strSQL);while(rs.next()){readername.addItem(rs.getString(1));}}catch(SQLExceptionsqle){}catch(Exceptionex){。
Java图书管理系统-附源码
图书信息删除:
图书信息显示:
图书借阅:
图书归还:
分析总结:
本程序在数据库设计方面可以改为多张表存储的方式,用三张表来记录图书信息,借阅关系和学生信息,这样可以减少数据冗余,还可以增加一些其他功能,比如图书挂失等功能。由于刚刚接触到Java界面设计,所以本程序在界面设计方面还有有待改进的地方。
JMenuItem itemDelete = new JMenuItem();
JMenuItem itemSelect = new JMenuItem();
JMenuItem itБайду номын сангаасmBook = new JMenuItem();
JMenuItem itemReturn = new JMenuItem();
图书ID,图书名称,图书所有者,图书的状态,图书使用者(允许为空)均为varchar(50)类型,在Java中可以方便的查询。图书存储信息的具体内容如下图所示:
功能模块:
程序设计:
主框架设计:
主框架上方包含三个按钮,分别是“系统管理”、“图书信息管理”和“图书流通管理”,定义JMenuBar类的对象、JMenu类的对象和JMenuItem类的对象,分别表示菜单栏、菜单组和菜单选项,然后调用初始化函数,将不同类的对象通过setText()函数设定不同的文本,然后将其添加到窗口容器中。对每个按钮分别添加不同的消息监听,响应相应的消息,调用不同的类完成不同的功能。消息监听功能详见源代码bookMain类。
删除图书信息模块:
调用bookDel类的构造函数产生一个该类的对象,在初始化函数中显示信息输入对话框,提示用户输入要删除图书的ID。完成输入后,点击确定按钮,消息监听模块将调用bookBean的构造函数产生一个该类的对象,通过该对象调用bookBean的bookDel函数,执行删除的SQL语句,通过delete语句完成图书信息的删除功能。
图书管理系统源码(java实现)
【图书管理系统】【MainPro包】1.系统登录页面public class Login extends Frame {private static final long serialVersionUID = -1758475247807861408L;TextField text_user;TextField text_pass;public Login() {1 this.setTitle("登录");this.setLayout(null);//默认流式布局this.setSize(260, 170);/* 定义标签与文本框*/Label lbUser = new Label("用户名:");text_user = new TextField();Label lbPass = new Label("密码:");text_pass = new TextField();Button btn_ok = new Button("确定");Button btn_cancel = new Button("取消");lbUser.setBounds(40, 53, 60, 20);//x,y,width,heightlbPass.setBounds(40, 83, 60, 20);text_user.setBounds(100, 50, 120, 20);text_pass.setBounds(100, 80, 120, 20);btn_ok.setBounds(45, 120, 80, 25); // 确定按钮btn_cancel.setBounds(135, 120, 80, 25); // 取消按钮/* 添加标签与文本框*/add(lbUser);add(lbPass);add(text_user);add(text_pass);add(btn_ok);add(btn_cancel);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置this.setVisible(true); // 使窗体可见btn_ok.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {btn_okActionPerformed(e);//自定义确定按钮触发的实施过程}}));btn_cancel.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}}));this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);} }); }public void btn_okActionPerformed(ActionEvent e) {String user = text_user.getText();String pass = text_pass.getText();String is_admin;// 如果用户名或密码任一为空,则终止后续操作if (user.equals("")||pass.equals("")) {JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");return;}try {// 核对用户名和密码String sql = "select * from user where username=" + "'" + user + "' and password=" + "'" + pass + "'";ResultSet rs = DbOp.executeQuery(sql);// 如果此用户存在,则记录其状态(否:不是管理员,是:是管理员)if (rs.next()) {is_admin = rs.getString("is_admin");} else {JOptionPane.showMessageDialog(null, "用户名或密码不正确!");return;}GlobalVar.login_user = user; // 记录登录的用户名ShowMain show = new ShowMain(); // 调用主程序// 只有管理员才能使用"基础管理"和"借阅管理"菜单show.setRights(is_admin);// 释放窗体及其全部组件的屏幕资源,即使释放登录窗体dispose(); // 释放当前窗体} catch (SQLException e1) {JOptionPane.showMessageDialog(null, "用户数据库有误!");}}}2.系统首页页面public class ShowMain extends Frame {private static final long serialVersionUID = 5003296786441785470L;MenuBar menuBar;Menu jcwh, jcwh_book, jcwh_reader;//基础维护:图书维护、读者维护Menu jywh, cxgl, xtgl;//借阅维护、查询管理、系统管理MenuItemjcwh_book_add,jcwh_book_update,jcwh_book_delete,jcwh_reader_add,jcwh_reader_update,jcwh_reader_delete;MenuItem jywh_borrow, jywh_back;MenuItem cxgl_book, cxgl_reader;MenuItem xtgl_update_pass, xtgl_exit;public void setRights(String rights) {// 如果不是管理员,则禁止用户维护图书信息和读者信息以及禁止进行借阅管理,即只能查询if (rights.equals("否")) {jywh.setEnabled(false);jcwh.setEnabled(false);}}public ShowMain() {setTitle("图书管理系统");setLayout(new BorderLayout());setSize(640, 480);menuBar = new MenuBar();jcwh = new Menu("基础维护");// 基础维护菜单jcwh_book = new Menu("图书维护");// 图书维护菜单jcwh_book_add = new MenuItem("添加");// 添加图书菜单jcwh_book_update = new MenuItem("修改");// 修改图书菜单jcwh_book_delete = new MenuItem("删除");// 删除图书菜单jcwh_reader = new Menu("读者维护");// 读者维护菜单jcwh_reader_add = new MenuItem("添加读者");// 添加读者菜单jcwh_reader_update = new MenuItem("修改读者");jcwh_reader_delete = new MenuItem("删除读者");jywh = new Menu("借阅管理");jywh_borrow = new MenuItem("借书管理");jywh_back = new MenuItem("还书管理");cxgl = new Menu("查询管理");cxgl_book = new MenuItem("图书查询");cxgl_reader = new MenuItem("读者查询");xtgl = new Menu("系统管理");xtgl_update_pass = new MenuItem("修改密码");xtgl_exit = new MenuItem("退出系统");// 添加图书菜单jcwh_book.add(jcwh_book_add);jcwh_book.add(jcwh_book_update);jcwh_book.add(jcwh_book_delete);jcwh.add(jcwh_book);jcwh_reader.add(jcwh_reader_add);jcwh_reader.add(jcwh_reader_update);jcwh_reader.add(jcwh_reader_delete);jcwh.add(jcwh_reader);jywh.add(jywh_borrow);jywh.add(jywh_back);cxgl.add(cxgl_book);cxgl.add(cxgl_reader);xtgl.add(xtgl_update_pass);xtgl.add(xtgl_exit);menuBar.add(jcwh);menuBar.add(jywh);menuBar.add(cxgl);menuBar.add(xtgl);setMenuBar(menuBar);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见jcwh_book_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("save");} });jcwh_book_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("update");} });jcwh_book_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("delete");} });jcwh_reader_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("save");} });jcwh_reader_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("update");} });jcwh_reader_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("delete");} });jywh_borrow.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Borrow();} });jywh_back.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Back();} });cxgl_book.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookQuery();} });cxgl_reader.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderQuery();} });xtgl_update_pass.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new UpdatePassword();} });xtgl_exit.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});}}3.图书管理public class BookManeger extends JFrame {private static final long serialVersionUID = 377287301994613384L;private Label lbbookid_c = new Label("图书编号");private TextField tf_bookid_c = new TextField();private Label lbbookid = new Label("图书编号");private TextField tf_bookid = new TextField();private Label lbbookname = new Label("图书名称");private TextField tf_bookname = new TextField();private Label lbbooktype = new Label("图书类别");private Choice tf_booktype = new Choice();private Label lbauthor = new Label("作者");private TextField tf_author = new TextField();private Label lbtranslator = new Label("译者");private TextField tf_translator = new TextField();private Label lbpublisher = new Label("出版社");private TextField tf_publisher = new TextField();private Label lbpublish_time = new Label("出版时间");private TextField tf_publish_time = new TextField();private Label lbprice = new Label("定价");private TextField tf_price = new TextField();private Label lbstock = new Label("库存数量");private TextField tf_stock = new TextField();private Button queryBtn = new Button("查询");private Button saveBtn = new Button("保存");private Button closeBtn = new Button("关闭");private String optionStr;BookManeger(String str) {optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid);map.put("bookname", tf_bookname);map.put("booktype", tf_booktype);map.put("author", tf_author);map.put("translator", tf_translator);map.put("publisher", tf_publisher);map.put("publish_time", tf_publish_time);map.put("price", tf_price);map.put("stock", tf_stock);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delActionPerformed(e, map);}else{i = Jcwh.btn_saveActionPerformed(e, map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "图书添加成功!";}else if(optionStr.equals("update")){showInfo = "图书修改成功!";}else if(optionStr.equals("delete")){showInfo = "图书删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});/* 关闭窗口*/this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setSize(500, 320);lbbookid.setBounds(50, 40, 50, 20); // 图书编号tf_bookid.setBounds(110, 40, 100, 20);lbbookname.setBounds(240, 40, 50, 20); // 图书名称tf_bookname.setBounds(300, 40, 100, 20);lbbooktype.setBounds(50, 80, 50, 20); // 图书类别tf_booktype.setBounds(110, 80, 100, 20);tf_booktype.add("科技");tf_booktype.add("文学");tf_booktype.add("社科");tf_booktype.add("其他");lbauthor.setBounds(240, 80, 50, 20); // 作者tf_author.setBounds(300, 80, 100, 20);lbtranslator.setBounds(50, 120, 50, 20); // 设置译者tf_translator.setBounds(110, 120, 100, 20);lbpublisher.setBounds(240, 120, 50, 20); // 出版社tf_publisher.setBounds(300, 120, 100, 20);lbpublish_time.setBounds(50, 160, 50, 20); // 出版时间tf_publish_time.setBounds(110, 160, 100, 20);lbprice.setBounds(240, 160, 50, 20); // 定价tf_price.setBounds(300, 160, 100, 20);lbstock.setBounds(50, 200, 50, 20); // 库存数量tf_stock.setBounds(110, 200, 100, 20);saveBtn.setBounds(150, 240, 80, 25); // 保存按钮closeBtn.setBounds(280, 240, 80, 25);// 关闭按钮if(str.equals("save")){setTitle("添加图书");}else if(str.equals("update")){setTitle("修改图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbbookid);add(tf_bookid);add(lbbookname);add(tf_bookname);add(lbbooktype);add(tf_booktype);add(lbauthor);add(tf_author);add(lbtranslator);add(tf_translator);add(lbpublisher);add(tf_publisher);add(lbpublish_time);add(tf_publish_time);add(lbprice);add(tf_price);add(lbstock);add(tf_stock);add(saveBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见}private void clearAllTextfield() {tf_bookid.setText("");tf_bookname.setText("");tf_author.setText("");tf_translator.setText("");tf_publisher.setText("");tf_publish_time.setText("");tf_price.setText("");tf_stock.setText("");}}4.读者管理public class ReaderManeger extends JFrame {private static final long serialVersionUID = -2399939451497711745L;Label lbreaderid_c = new Label("读者编号");TextField tf_readerid_c = new TextField();Label lbreaderid = new Label("读者编号");TextField tf_readerid = new TextField();Label lbreadername = new Label("读者姓名");TextField tf_readername = new TextField();Label lbreadertype = new Label("读者类别");Choice tf_readertype = new Choice();Label lbsex = new Label("性别");Choice tf_sex = new Choice();Label lbmax_num = new Label("可借数量");TextField tf_max_num = new TextField();Label lbdays_num = new Label("可借天数");TextField tf_days_num = new TextField();Button queryBtn = new Button("查询");Button saveBtn = new Button("保存");Button closeBtn = new Button("关闭");private String optionStr;//保存、修改、删除ReaderManeger(String str){optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid);map.put("readername", tf_readername);map.put("readertype", tf_readertype);map.put("sex", tf_sex);map.put("days_num", tf_days_num);map.put("max_num", tf_max_num);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delReaderActionPerformed(e, map);}else{i = Jcwh.btn_saveReaderActionPerformed(e,map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "读者添加成功!";}else if(optionStr.equals("update")){showInfo = "读者修改成功!";}else if(optionStr.equals("delete")){showInfo = "读者删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setTitle("添加读者信息");setSize(500, 230);lbreaderid.setBounds(50, 50, 50, 20);tf_readerid.setBounds(110, 50, 100, 20);lbreadername.setBounds(240, 50, 50, 20);tf_readername.setBounds(300, 50, 100, 20);lbreadertype.setBounds(50, 80, 50, 20);tf_readertype.setBounds(110, 80, 100, 20);tf_readertype.add("教师");tf_readertype.add("学生");tf_readertype.add("职工");lbsex.setBounds(240, 80, 50, 20);tf_sex.setBounds(300, 80, 100, 20);tf_sex.add("男");tf_sex.add("女");lbmax_num.setBounds(50, 110, 50, 20);tf_max_num.setBounds(110, 110, 100, 20);lbdays_num.setBounds(240, 110, 50, 20);tf_days_num.setBounds(300, 110, 100, 20);saveBtn.setBounds(150, 150, 80, 25);closeBtn.setBounds(280, 150, 80, 25);if(str.equals("save")){setTitle("添加读者");}else if(str.equals("update")){setTitle("修改读者");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbreaderid);add(lbreadername);add(lbreadertype);add(lbsex);add(lbmax_num);add(lbdays_num);add(tf_readerid);add(tf_readername);add(tf_max_num);add(tf_days_num);add(tf_readertype);add(tf_sex);add(saveBtn);add(closeBtn);setLocationRelativeTo(null);setVisible(true);}private void clearAllTextfield() {tf_readerid.setText("");tf_readername.setText("");tf_max_num.setText("");tf_days_num.setText("");}public static void main(String[] args) {ReaderManeger r = new ReaderManeger("update");}}5.借书public class Borrow extends Frame {private static final long serialVersionUID = -1036076990599464079L;String SepLine = "-------------------------------------------------";Label lbbookid = new Label("图书编号");Label lbreaderid = new Label("读者编号");TextField tf_bookid = new TextField();TextField tf_readerid = new TextField();Button queryBtn = new Button("查询");Label lbbookinfo = new Label(SepLine + "图书信息" + SepLine); Label lbbookname = new Label("图书名称:");Label tf_bookname = new Label("xx");Label lbauthor = new Label("作者:");Label tf_author = new Label("xx");Label lbpublisher = new Label("出版社:");Label tf_publisher = new Label("xx");Label lbpublish_time = new Label("出版时间:");Label tf_publish_time = new Label("xx");Label lbprice = new Label("定价:");Label tf_price = new Label("xx");Label lbstock = new Label("库存数量:");Label tf_stock = new Label("xx");Label lbreaderinfo = new Label(SepLine + "读者信息" + SepLine); Label lbreadername = new Label("读者姓名:");Label tf_readername = new Label("xx");Label lbreadertype = new Label("读者类型:");Label tf_readertype = new Label("xx");Label lbmax_num = new Label("最大可借数:");Label tf_max_num = new Label("xx");Label lbdays_num = new Label("最大可借天数:");Label tf_days_num = new Label("xx");Label lbborrowinfo = new Label(SepLine + "借阅信息" + SepLine); Label lbborrowednum = new Label("该读者已借图书数量:"); Label tf_borrowednum = new Label("xx");Label lbif_borrow = new Label("该读者是否可借所选图书:"); Label tf_if_borrow = new Label("xx");Label lbborrow_date = new Label("借阅日期:");Label tf_borrow_date = new Label("xx");Button borrowBtn = new Button("借出");Button closeBtn = new Button("关闭");public Borrow() {setLayout(null);setTitle("借阅图书");setSize(500, 420);this.setForeground(Color.BLACK); // 设置前景色为黑色lbbookid.setBounds(30, 40, 50, 25); // 图书编号tf_bookid.setBounds(90, 40, 90, 20);lbreaderid.setBounds(200, 40, 50, 25); // 读者编号tf_readerid.setBounds(260, 40, 90, 20);queryBtn.setBounds(370, 40, 80, 25); // 查询按钮lbbookinfo.setBounds(30, 70, 440, 25); // 图书信息提示条lbbookname.setBounds(30, 100, 60, 25); // 图书名称tf_bookname.setBounds(90, 100, 200, 25);lbauthor.setBounds(310, 100, 60, 25); // 作者tf_author.setBounds(370, 100, 90, 25);lbpublisher.setBounds(30, 125, 60, 25); // 出版社tf_publisher.setBounds(90, 125, 200, 25);lbpublish_time.setBounds(310, 125, 60, 25); // 出版时间tf_publish_time.setBounds(370, 125, 90, 25);lbprice.setBounds(30, 150, 60, 25); // 定价tf_price.setBounds(90, 150, 200, 25);lbstock.setBounds(310, 150, 60, 25); // 库存数量tf_stock.setBounds(370, 150, 90, 25);lbreaderinfo.setBounds(30, 180, 440, 25); // 读者信息提示条lbreadername.setBounds(30, 205, 60, 25); // 读者姓名tf_readername.setBounds(90, 205, 90, 25);lbreadertype.setBounds(310, 205, 60, 25); // 读者类型tf_readertype.setBounds(370, 205, 90, 25);lbmax_num.setBounds(30, 230, 75, 25); // 最大可借数tf_max_num.setBounds(105, 230, 90, 25);lbdays_num.setBounds(310, 230, 85, 25); // 最大可借天数tf_days_num.setBounds(395, 230, 70, 25);lbborrowinfo.setBounds(30, 260, 440, 25); // 借阅信息提示条lbborrowednum.setBounds(30, 285, 120, 25);// 已借图书数量tf_borrowednum.setBounds(150, 285, 50, 25);lbif_borrow.setBounds(30, 310, 145, 25); // 是否可借tf_if_borrow.setBounds(175, 310, 50, 25);lbborrow_date.setBounds(30, 335, 60, 25);// 借书日期tf_borrow_date.setBounds(90, 335, 100, 25);borrowBtn.setBounds(160, 365, 80, 25);// 借出按钮borrowBtn.setEnabled(false); // 开始时禁用借出按钮closeBtn.setBounds(260, 365, 80, 25);// 关闭按钮queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_querywActionPerformed(e); } }); borrowBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_borrowActionPerformed(e); } });closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { setForeground(Color.BLACK); dispose(); } }); this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setForeground(Color.BLACK); // 设置前景色为黑色dispose(); // 关闭窗体}});add(lbbookid);add(lbreaderid);add(queryBtn);add(lbbookinfo);add(lbbookname);add(lbauthor);add(lbpublisher);add(lbpublish_time);add(lbprice);add(lbstock);add(lbreaderinfo);add(lbreadername);add(lbreadertype);add(lbmax_num);add(lbdays_num);add(lbborrowinfo);add(lbborrowednum);add(lbif_borrow);add(lbborrow_date);add(borrowBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见setForeground(Color.RED); // 设置前景色为红色add(tf_bookid);add(tf_readerid);add(tf_bookname);add(tf_author);add(tf_publisher);add(tf_publish_time);add(tf_price);add(tf_stock);add(tf_readername);add(tf_readertype);add(tf_max_num);add(tf_days_num);add(tf_borrowednum);add(tf_if_borrow);add(tf_borrow_date);}// 图书和读者查询private void btn_querywActionPerformed(ActionEvent e) {String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();// 如果图书编号或读者编号两者均为空,或者有一个为空,则返回if (bookid.equals("") || readerid.equals("")) {JOptionPane.showMessageDialog(null, "图书编号和读者编号均不能为空!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询图书,结果存入book对象中Book book = BookSelect.SelectBookById(bookid);if (book != null) { // 如果查询到结果,将其显示在各文本框中tf_bookname.setText(book.getBookname());tf_author.setText(book.getAuthor());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf((book.getPrice())));tf_stock.setText(String.valueOf(book.getStock()));} else {JOptionPane.showMessageDialog(null, "图书编号有误,查无此书!");init(); // 重新初始化各参数并禁止借出按钮return;}if (book.getStock() == 0) {JOptionPane.showMessageDialog(null, "图书已无库存,无法借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询读者,结果存入reader对象中Reader reader = ReaderSelect.selectReaderById(readerid);// 如果查询到结果,将其显示在各文本框中if (reader != null) {tf_readername.setText(reader.getReadername());tf_readertype.setText(reader.getReadertype());tf_max_num.setText(String.valueOf(reader.getMax_num()));tf_days_num.setText(String.valueOf(reader.getDays_num()));} else {JOptionPane.showMessageDialog(null, "读者编号有误,查无此人!");init(); // 重新初始化各参数并禁止借出按钮return;}// 查询指定读者是否已借过指定图书且未归还if (IfBorrowBack.findbook(bookid, readerid)) {JOptionPane.showMessageDialog(null, "该读者已借阅所选图书,且未归还!");init(); // 重新初始化各参数并禁止借出按钮return;}// 统计读者所借图书数量int borrowednum = statborrowednum(readerid);tf_borrowednum.setText(String.valueOf(borrowednum));// 如果读者已借图书尚未超出其允许最大借书量,则允许其继续借阅所选图书if (borrowednum < reader.getMax_num()) {tf_if_borrow.setText("是");// 创建一个简单日期格式对象,注意:MM一定要用大写SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 创建日期变量,其内容为当前日期Date currentdate = new Date();// 将日期按指定格式输出String borrowdate = sdf.format(currentdate);tf_borrow_date.setText(borrowdate);borrowBtn.setEnabled(true); // 使借出按钮有效} else {JOptionPane.showMessageDialog(null, "该读者借书过多,无法继续借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}}// 填写借出图书记录private void btn_borrowActionPerformed(ActionEvent e) {String sql;String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();String borrowdate = tf_borrow_date.getText();// 为borrow表增加借书记录sql = "insert into borrow (book_id,reader_id,"+ "borrow_date,if_back) values('" + bookid + "','" + readerid + "','" + borrowdate + "','否')";。
图书借阅管理系统java代码
以我给的标题写原创文档,最低1200字,要求以Markdown文本格式输出,不要带图片和AI、人工智能、Markdown、GPT等关键词,标题为:图书借阅管理系统java代码# 图书借阅管理系统Java代码## 一、介绍图书借阅管理系统是一个帮助图书馆管理图书借阅情况的系统。
本系统基于Java开发,采用面向对象的编程方式,实现了对图书信息、借阅记录等数据的管理与处理。
用户可以通过该系统查询图书信息、借阅图书、归还图书,并实现了管理员对系统的管理功能。
## 二、功能模块### 1. 图书管理模块- 实现对图书信息的添加、删除、修改和查询功能。
- 对图书的分类管理,方便用户按照分类查找图书信息。
### 2. 用户管理模块- 用户注册与登录功能,保证用户数据的安全。
- 用户查询借阅情况、借阅历史等个人信息。
### 3. 借阅管理模块- 实现图书的借阅功能,包括借书日期、归还日期等信息的记录。
- 用户借阅超时提醒,确保图书及时归还。
### 4. 管理员模块- 管理员登录后可以对图书信息、用户信息进行管理。
- 实现图书归还、逾期处理等功能。
## 三、系统架构本系统采用MVC(Model-View-Controller)架构,实现了模型层、视图层、控制层之间的分离,提高了系统的灵活性和可维护性。
具体架构如下:1. Model层:负责处理数据的逻辑操作,包括对图书信息、用户信息、借阅记录等数据的管理。
2. View层:负责系统的界面展示,包括用户界面和管理员界面。
3. Controller层:负责处理用户请求,调用Model层的方法,并将结果返回给View层进行展示。
## 四、代码示例以下是借阅图书的Java代码示例:```javapublic class BorrowBook {private Book book;private User user;private Date borrowDate;private Date returnDate;// Constructorpublic BorrowBook(Book book, User user, Date borrowDate, Date returnDate) {this.book = book;er = user;this.borrowDate = borrowDate;this.returnDate = returnDate;}// Getters and setters}```以上代码实现了一个借阅图书的类`BorrowBook`,包含了借阅的图书信息、用户信息,借阅时间和归还时间。
java 10套完整项目开发案例
在当今信息化的社会中,Java作为一种高性能、跨评台的编程语言,被广泛应用于企业级应用开发、大规模数据处理、云计算等诸多领域。
作为Java开发者,我们需要不断提升自己的编程能力,不仅仅要掌握Java的基础知识,还需要了解其在实际项目中的应用。
本文将针对Java 10套完整项目开发案例进行深入探讨,为大家提供全面、高质量的实战经验。
一、全球信息站书店项目1.项目概述全球信息站书店项目是一个基于Java开发的B2C电子商务项目,主要包括商品管理、订单管理、用户管理、购物车管理等模块。
该项目使用Spring框架进行搭建,集成了Spring MVC、MyBatis等关键技术,实现了对书籍的展示、购物、评价等功能。
2.技术栈Spring框架、Spring MVC、MyBatis、MySQL数据库、Bootstrap前端框架、JSP页面模板等。
3.实现功能(1)书籍展示:展示各种类型的图书,并提供搜索、分类等功能。
(2)购物车管理:用户可以将书籍加入购物车,查看购物车内的商品,并进行结算。
(3)订单管理:用户可以查看历史订单、下单、取消订单等操作。
(4)用户管理:用户注册、登入、注销、修改个人信息等功能。
二、学生信息管理系统1.项目概述学生信息管理系统是一个基于Java开发的校园信息管理系统,主要包括学生信息管理、课程管理、成绩管理、教师管理等模块。
该项目使用SSM框架进行搭建,实现了对学生信息、教师信息以及课程信息的增删改查功能,同时还支持成绩的录入与查询。
2.技术栈SSM框架、MySQL数据库、Maven项目管理工具、JSP页面模板、Bootstrap前端框架等。
3.实现功能(1)学生信息管理:包括学生的基本信息、课程信息、成绩信息等管理。
(2)教师信息管理:包括教师的基本信息、授课信息等管理。
(3)课程管理:包括课程的增删改查。
(4)成绩管理:教师可以录入学生成绩,学生可以查询自己的成绩。
三、餐厅点餐系统1.项目概述餐厅点餐系统是一个基于Java开发的餐饮业务管理系统,主要包括餐厅管理、菜品管理、订单管理等模块。
Java_项目开发实例_图书信息管理系统开发文档及源码
图书信息管理系统一、系统功能概述:根据图书信息管理系统的特点,可以将本系统分为2大功能模块,分别为:基础数据维护、系统数据维护。
本系统各个部分及其包括的具体功能模块如下图所示:二、数据库设计:图书信息表:字段名说明类型长度及备注ISBN国际标准书号Varchar(13)主键图书类别表:用户信息表:读者信息表:三、系统源代码:Com.zhang.dao:Dao.java //数据库的连接与操作类package com.zhang.dao;import java.sql.Connection;import java.sql.Date;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.zhang.model.BookInfo;import com.zhang.model.BookType;import com.zhang.model.Operator;import com.zhang.model.Reader;import er;public class Dao {protected static String dbClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";protected static String dbUrl = "jdbc:sqlserver://localhost:1433;"+ "DatabaseName=db_lib;SelectMethod=Cursor";protected static String dbUser = "sa";protected static String dbPwd = "zhangyong";protected static String second = null;private static Connection conn = null;//创建数据库连接private Dao() {try {if (conn == null) {Class.forName(dbClassName).newInstance();conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);System.out.println("数据库连接成功!");}elsereturn;} catch (Exception ee) {ee.printStackTrace();}}//执行查询private static ResultSet executeQuery(String sql) {try {if(conn==null)new Dao();returnconn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql);} catch (SQLException e) {e.printStackTrace();return null;} finally {}}//执行更新private static int executeUpdate(String sql) {try {if(conn==null)new Dao();return conn.createStatement().executeUpdate(sql);} catch (SQLException e) {System.out.println(e.getMessage());//if(e.getMessage().equals("[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE 语句与COLUMN REFERENCE 约束 'FK_TB_BORRO_REFERENCE_TB_BOOKI' 冲突。
用java做的一个图书管理系统的源代码
用java做的一个图书管理系统的源代码import java.sql.*;import java.util.*;public class T{public static void main(String[] args) throws Exception{Connection conn=null;Statement stmt=null;ResultSet rs=null;while(true){Scanner scanner=new Scanner(System.in);System.out.println("请输入用户名:");String username2=scanner.next();System.out.println("请输入密码:");String password2=scanner.next();if(!(username2.equals("")||password2.equals(""))){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection("jdbc:odbc:book","","");String sql="select * from ww where username='"+username2+"'";stmt=conn.createStatement();rs=stmt.executeQuery(sql);if(rs.next()){if(rs.getString("password").equals(password2)){System.out.println("*********欢迎来山东科技大学图书馆管理系统********");while(true){System.out.println(" 1.图书信息");System.out.println(" 2.读者信息");System.out.println(" 3.管理员信息");System.out.println(" 4.借阅信息");System.out.println(" 5.还书信息");System.out.println(" 6.逾期罚款或损坏赔偿信息");//System.out.println(" 7.退出");System.out.println(" 请输入选择功能的序号:");int a=scanner.nextInt();switch(a){case 1:System.out.println(" 图书信息: ");System.out.println(" 1. 查询图书信息: ");System.out.println(" 2. 插入图书信息: ");System.out.println(" 3. 删除图书信息: ");System.out.println(" 4. 修改图书信息: ");int a1=scanner.nextInt();switch(a1){case 1:System.out.println(" 欢迎进入图书信息查询系统: ");System.out.println(" 1. 无条件查询图书信息: ");System.out.println(" 2. 条件查询图书信息: ");int d=scanner.nextInt();switch(d){case 1:int llll=0;//int mm=0;while(llll!=1){System.out.println(" 1. 无条件查询图书信息: ");String Sql0 = "SELECT * FROM systembook ";rs= stmt.executeQuery(Sql0);while(rs.next()){String bookID =rs.getString(1);String bookNo =rs.getString(2);String bookName =rs.getString(3);String bookWriter =rs.getString(4);String bookPub =rs.getString(5);System.out.println(bookID+","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){llll=1;System.out.println();};}break;//break;case 2:System.out.println(" 2. 条件查询图书信息: ");System.out.println(" 1. 单条件查询图书信息: ");System.out.println(" 2. 模糊条件查询图书信息: ");System.out.println(" 3. 多表连接查询图书信息: ");System.out.println(" 4. 嵌套查询图书信息: ");System.out.println(" 5. 谓词演算查询");int c12=scanner.nextInt();switch(c12){case 1:System.out.println(" 1.单条件查询: ");System.out.println(" 1.按图书名编码号查询图书信息: ");int ddd=0;while(ddd!=1){System.out.println("请输入图书编码号:");String A=scanner.next();String sql1= "SELECT * FROM systembook WHERE bookID ='"+A+"' ";rs= stmt.executeQuery(sql1);int x=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);x++;}if(x==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续按姓名查询?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){ddd=1;System.out.println();};};}break;case 2:System.out.println(" 2.模糊查询图书信息: ");int dc=0;while(dc!=1){System.out.println("请用户输入图书名字中的模糊关键字");String E=scanner.next();String sq123= "SELECT * FROM systembook WHERE bookName LIKE'"+E+"%'";rs= stmt.executeQuery(sq123);int z=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);z++;}if(z==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续输入图书名字中的模糊关键字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){dc=1;System.out.println();// break;};}}break;case 3:System.out.println(" 3.多表连接查询查询图书信息: ");int dq=0;while(dq!=1){System.out.println("查询逾期罚款或是赔偿表中的读者的相关信息");System.out.println("请输入逾期罚款或是赔偿的读者编码号");String F=scanner.next();String sq1234= "SELECT * FROM fine,borrowbook,systemreader WHERE fine.bookID=borrowbook.bookID AND borrowbook.reaID=systemreader.reaID AND fine.bookID='"+F+"' ";rs= stmt.executeQuery(sq1234);int n=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);n++;}if(n==0){System.out.println("查无此人,请重新输入");}else{System.out.println("是否继续输入图书名字中的模糊关键字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){ddd=1;System.out.println();};}}break;case 4:System.out.println(" 4.嵌套查询图书信息: ");int dq1=0;System.out.println("查询某读者所在年级女读者的相关信息");System.out.println("请输入某读者的读者编号");String G=scanner.next();String sq12345= "SELECT * FROM systemreader WHERE reaGrade=(SELECT reaGrade FROM systemreader WHERE reaID='"+G+"') AND reasex='女'";rs= stmt.executeQuery(sq12345);int m=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);m++;}if(m==0){System.out.println("查无此书,请重新输入");}else{System.out.println("是否继续输入读者编号?yes/no no 返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){d=1;System.out.println();};}}break;System.out.println(" 5. 谓词演算查询:");int dq1123=0;while(dq1123!=1){System.out.println("查询借阅了某本书的读者的相关信息");System.out.println("请输入该书的名字");String H=scanner.next();String sq123456= "SELECT * FROM systemreader WHERE reaID IN (SELECT reaID FROM borrowbook WHERE bookName='"+H+"')";rs= stmt.executeQuery(sq123456);int l=0;while(rs.next()){String a2 =rs.getString(1);String b2 =rs.getString(2);String c2 =rs.getString(3);String d2 =rs.getString(4);String e2 =rs.getString(5);System.out.println(a2+","+b2+" ,"+c2+","+d2+","+e2);l++;}if(l==0){System.out.println("查无此人,请重新输入");}else{System.out.println("是否继续输入图书名字?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){d=1;System.out.println();};}}break;}//c12break;}break;/*case 1:System.out.println(" 1. 查询图书信息: ");String Sql = "SELECT * FROM systembook ";rs= stmt.executeQuery(Sql);while(rs.next()){//String str =scanner.next();String bookID =rs.getString(1);String bookNo =rs.getString(2);String bookName =rs.getString(3);String bookWriter =rs.getString(4);String bookPub =rs.getString(5);System.out.println(bookID+","+bookNo+","+bookName+","+ bookWriter+","+bookPub);}break;*/case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入图书信息: ");System.out.println("请按顺序插入图书条码号,图书索书号,图书名字,图书作者,图书出版社");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String insertSql="INSERT INTO systembook(bookID,bookNo,bookName,bookWriter,bookPub)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"')";int i=stmt.executeUpdate(insertSql); //返回记录影响的条数if(i!=0){System.out.println("插入成功!"); }System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;//int mm=0;while(ll!=1){System.out.println(" 3. 删除图书信息: ");System.out.println("请输入要删除的图书编号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM systembook where bookID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){System.out.println( "没有这本书,请重新输入");}else{{String deleSql= "DELETE FROM systembook WHERE bookID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改图书信息: ");System.out.println("请输入修改的图书ID ");String S=scanner.next();String sql1="SELECT * FROM systembook where bookID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){System.out.println( "没有这本书,请重新输入");}else{System.out.println("要将书名改为");String bbb=scanner.next();String updateSql1="UPDATE systembook SET bookName='"+bbb+"' WHERE bookID='"+S+"'";int hh=stmt.executeUpdate(updateSql1); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;}break;/* String updateSql="UPDATE systembook SET bookCopy='"+c1+"' WHERE bookName='数据库管理'";int t=stmt.executeUpdate(updateSql); //返回记录影响的条数if(t!=0){System.out.println("修改成功!");}break;}break;*/case 2:System.out.println(" 读者信息: ");System.out.println(" 1. 查询读者信息: ");System.out.println(" 2. 插入读者信息: ");System.out.println(" 3. 删除读者信息: ");System.out.println(" 4. 修改读者信息: " );int b1=scanner.nextInt();switch(b1){case 1:System.out.println(" 1. 查询读者信息: ");String ssql = "SELECT * FROM systemreader ";rs= stmt.executeQuery(ssql);while(rs.next()){//String str =scanner.next();String reaID=rs.getString(1);String reaName =rs.getString(2);String reaLBID =rs.getString(3);String reaNo =rs.getString(4);String reaSex =rs.getString(5);String reaType =rs.getString(6);String reaDep =rs.getString(7);String reaGrade =rs.getString(8);String reaPre =rs.getString(9);String reaDate =rs.getString(10);System.out.println(reaID+","+reaName+","+reaNo+","+reaSex+","+reaLBID+","+reaType+","+reaD ep+","+reaGrade+","+reaPre+","+reaDate);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入读者信息: ");System.out.println("请按顺序插入借书卡证号读者名字读者学号读者性别读者LBID 读者类型读者学院读者年级读者专业办证日期");String str=scanner.next();String []splitst=str.split(",");String b11=splitst[0];String b12=splitst[1];String b13=splitst[2];String b14=splitst[3];String b15=splitst[4];String b16=splitst[5];String b17=splitst[6];String b18=splitst[7];String b19=splitst[8];String b20=splitst[9];String insertSql="INSERT INTO systemreader(reaID,reaName,reaNo,reaSex,reaLBID,reaType,reaDep,reaGrade,reaPre,reaDate) VALUES('"+b11+"','"+b12+"','"+b13+"','"+b14+"','"+b15+"','"+b16+"','"+b17+"','"+b18+"','"+b19+"' ,'"+b20+"')";int n=stmt.executeUpdate(insertSql); //返回记录影响的条数if(n!=0){System.out.println("插入成功!"); }System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除读者信息: ");System.out.println("请输入要删除的读者证号:");String Str=scanner.next();String []Splitst=Str.split(",");String r=Splitst[0];String sql1="SELECT * FROM systemreader where reaID='"+r+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);String g22 =rs.getString(7);String h22 =rs.getString(8);String i22 =rs.getString(9);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22+","+g22+","+h22+","+i22);kkk++;}if(kkk==0){System.out.println( "没有这个读者,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM systemreader WHERE reaID='"+r+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}/* String deleSql= "DELETE FROM systemreader WHERE reaID='"+r+"'";int m=stmt.executeUpdate(deleSql); //返回记录影响的条数if(m!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改读者信息: ");System.out.println("请输入修改以后的读者的ID ");String S=scanner.next();// String []Ssplitst=S.split(",");//String tt=Ssplitst[0];String sql1="SELECT * FROM systemreader where reaID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);String g222 =rs.getString(7);String h222 =rs.getString(8);String i222 =rs.getString(9);String j222 =rs.getString(10);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222+","+g222+","+h222+", "+i222+","+j222);lll++;}if(lll==0){System.out.println( "没有这个人,请重新输入");}else{System.out.println("要将名字改为");String bb=scanner.next();String updateSql="UPDATE systemreader SET reaName='"+bb+"' WHERE reaID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;/* String updateSql="UPDATE systemreader SET reaSex='"+tt+"' WHERE reaID='20030101'";int l=stmt.executeUpdate(updateSql); //返回记录影响的条数if(l!=0){System.out.println("修改成功!");}break;*/}break;case 3:System.out.println(" 管理员信息: ");System.out.println(" 1. 查询管理员信息: ");System.out.println(" 2. 插入管理员信息: ");System.out.println(" 3. 删除管理员信息: ");System.out.println(" 4. 修改管理员信息: ");System.out.println(" 5. 返回上一级");int c11=scanner.nextInt();switch(c11){case 1:System.out.println(" 1. 查询管理员信息: ");String Ssql = "SELECT * FROM manager ";rs= stmt.executeQuery(Ssql);while(rs.next()){// String str =scanner.next();String mID =rs.getString(1);String mName=rs.getString(2);String mSex =rs.getString(3);System.out.println(mID+","+mName+","+mSex);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入管理员信息: ");System.out.println("请按顺序插入管理员的编号,管理员的姓名,管理员的性别,所管书库,电话,地址");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];String a15=splitst[4];String a16=splitst[5];String insertSql="INSERT INTO manager(mID,mName,mSex,mAuth,mTeleph,mAddre)VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"','"+a15+"','"+a16+"')";int i=stmt.executeUpdate(insertSql); //返回记录影响的条数if(i!=0){System.out.println("插入成功!");}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除管理员信息: ");System.out.println("请输入要删除的管理员编号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM manager where mID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);String e22 =rs.getString(5);String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22+","+e22+","+f22);kkk++;}if(kkk==0){System.out.println( "没有这个管理员,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM manager WHERE mID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};};}}/* String deleSql= "DELETE mID FROM manager WHERE mID='"+b3+"'";int k=stmt.executeUpdate(deleSql); //返回记录影响的条数if(k!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1){System.out.println(" 4. 修改管理员信息: ");System.out.println("请输入要修改的管理员编号:");String S=scanner.next();String []Ssplitst=S.split(",");String c1=Ssplitst[0];String sql1="SELECT * FROM manager where mID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);String e222 =rs.getString(5);String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222+","+e222+","+f222);lll++;}if(lll==0){System.out.println( "没有这个管理员,请重新输入");}else{// System.out.println( "要修改的信息");//String aa=scanner.next();System.out.println("要将它改为");String bb=scanner.next();String updateSql="UPDATE manager SET mName='"+bb+"' WHERE mID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}}break;}break;/*String updateSql="UPDATE manager SET mSex='"+c1+"' WHERE mID=1";int t=stmt.executeUpdate(updateSql); //返回记录影响的条数if(t!=0){System.out.println("修改成功!");}}break;*/case 4:System.out.println(" 图书借阅信息: ");System.out.println(" 1. 查询图书借阅信息信息: ");System.out.println(" 2. 插入图书借阅信息: ");System.out.println(" 3. 删除图书借阅信息: ");System.out.println(" 4. 修改图书借阅信息: ");System.out.println(" 5. 返回上一级");int d=scanner.nextInt();switch(d){case 1:System.out.println(" 1. 查询图书借阅信息: ");String Sql4 = "SELECT * FROM borrowbook ";rs= stmt.executeQuery(Sql4);while(rs.next()){String bookID =rs.getString(1);String reaID =rs.getString(2);String outDate =rs.getString(3);String yhDate =rs.getString(4);System.out.println(bookID+","+reaID+","+outDate+","+yhDate);}break;case 2:int zz=0;while(zz!=1){System.out.println(" 2. 插入图书借阅信息: ");System.out.println("请按顺序插入图书的的编号,读者编号,图书借出日期,图书归还日期");String str=scanner.next();String []splitst=str.split(",");String a11=splitst[0];String a12=splitst[1];String a13=splitst[2];String a14=splitst[3];//String a15=splitst[4];//String a16=splitst[5];String insertSql="INSERT INTO borrowbook(bookID,reaID,outDate,yhDate) VALUES('"+a11+"','"+a12+"','"+a13+"','"+a14+"')";int ii=stmt.executeUpdate(insertSql); //返回记录影响的条数if(ii!=0){System.out.println("插入成功!");}System.out.println("是否继续插入?yes/no no返回主菜单");String k=scanner.next();if(k.startsWith("yes")){System.out.println();};if(k.startsWith("no")){zz=1;System.out.println();};}break;case 3:int ll=0;while(ll!=1){System.out.println(" 3. 删除图书借阅信息: ");System.out.println("请输入要删除的图书条码号:");String Str=scanner.next();String []Splitst=Str.split(",");String b3=Splitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+b3+"'";rs= stmt.executeQuery(sql1);int kkk=0;while(rs.next()){String a22 =rs.getString(1);String b22 =rs.getString(2);String c22 =rs.getString(3);String d22 =rs.getString(4);// String e22 =rs.getString(5);//String f22 =rs.getString(6);System.out.println(a22+","+b22+" ,"+c22+","+d22);kkk++;}if(kkk==0){System.out.println( "没有这本书,请重新输入");}else{//System.out.println( "您是否真的要删除? yes/no");//String k=scanner.next();//if(k.startsWith("y")){String deleSql= "DELETE FROM borrowbook WHERE bookID='"+b3+"'";int p=stmt.executeUpdate(deleSql); //返回记录影响的条数if(p!=0){System.out.println("删除成功!");}System.out.println("是否继续删除?yes/no no返回主菜单");String l=scanner.next();if(l.startsWith("yes")){System.out.println();};if(l.startsWith("no")){ll=1;System.out.println();};}}}/* String deleSql= "DELETE bookID FROM borrowbook WHERE bookID='"+b3+"'";int k=stmt.executeUpdate(deleSql); //返回记录影响的条数if(k!=0){System.out.println("删除成功!");}*/break;case 4:int mm=0;while(mm!=1)System.out.println(" 4. 修改借阅读书信息: ");System.out.println("请输入要修改的图书的ID ");String S=scanner.next();String []Ssplitst=S.split(",");String c1=Ssplitst[0];String sql1="SELECT * FROM borrowbook where bookID='"+S+"'";rs= stmt.executeQuery(sql1);int lll=0;while(rs.next()){String a222 =rs.getString(1);String b222 =rs.getString(2);String c222 =rs.getString(3);String d222 =rs.getString(4);//String e222 =rs.getString(5);//String f222 =rs.getString(6);System.out.println(a222+","+b222+" ,"+c222+","+d222);lll++;}if(lll==0){System.out.println( "没有这条记录,请重新输入");}else{// System.out.println( "要修改的信息");//String aa=scanner.next();System.out.println("要将借阅日期改为");String bb=scanner.next();String updateSql="UPDATE borrowbook SET outDate='"+bb+"' WHERE bookID='"+S+"'";int hh=stmt.executeUpdate(updateSql); //返回记录影响的条数if(hh!=0){System.out.println("修改成功!");}System.out.println("是否继续修改yes/no no返回主菜单");String o=scanner.next();if(o.startsWith("yes")){System.out.println();};if(o.startsWith("no")){mm=1;System.out.println();};}break;}break;。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;import class book_add extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,addr ess;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息");c=getContentPane();(new BorderLayout());book_id_label=new JLabel("编号",;book_name_label=new JLabel("名称",; author_label=new JLabel("作者",;press_label=new JLabel("出版社",;press_date_label=new JLabel("出版日期",; price_label=new JLabel("价格",;book_num_label=new JLabel("库存数",; borrowed_num_label=new JLabel("已借阅数",; address=new JLabel("藏书地址",;book_id_TextField=new JTextField(15); book_name_TextField=new JTextField(15); author_TextField=new JTextField(15); press_TextField=new JTextField(15);press_date_TextField=new JTextField(15); price_TextField=new JTextField(15);book_num_TextField=new JTextField(15); borrowed_count=new JTextField(15); ("0");addresst=new JComboBox();("扬子津图书馆");("荷花池图书馆");("瘦西湖图书馆"); ("淮海路图书馆"); panel1=new JPanel(); (new GridLayout(9,2)); (book_id_label); (book_id_TextField); (book_name_label); (book_name_TextField); (press_label);(press_TextField); (author_label); (author_TextField); (press_date_label); (press_date_TextField); (price_label);(price_TextField); (book_num_label); (book_num_TextField); (borrowed_num_label); (borrowed_count); (address); (addresst);panel2=new JPanel();(new GridLayout(1,3));clear=new JButton("清空");(this);add=new JButton("添加");(this);exit=new JButton("退出");(this);(clear);(add);(exit);(panel1,;(panel2,;setVisible(true);}public void actionPerformed(ActionEvent e) {if()==exit){();}else if()==clear){("");("");("");("");("");("");("");}else if()==add){if().trim().equals("")){(null, "书号不能为空");}else if().trim().equals("")){(null, "书名不能为空");}else if().trim().equals("")){(null, "作者不能为空");}else if().trim().equals("")){(null, "出版社不能为空"); }else if().trim().equals("")){(null, "出版日期不能为空"); }else if().trim().equals("")){(null, "价格不能为空");}else if().trim().equals("")){(null, "库存不能为空");}else if().trim().equals("")){(null, "借阅数不能为空"); }else {try{String strSQL="insert into book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count,st ore_address) values('"+().trim()+"','"+().trim()+"','"+().trim()+"','"+().trim()+"','"+().trim()+"','"+().trim()+"','"+().trim()+"','"+().trim()+"','"+()+"')";if(strSQL)){();(null,"添加图书成功");}else{(null,"添加图书失败");();}();}catch(Exception ex){}}}}}package library;import .*;import .*;import class book_delete extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JLabel TipLabel=new JLabel("请选择要删除的书名",;JComboBox bb=new JComboBox();JButton yes,exit;JPanel panel1=new JPanel();public book_delete(){super("删除图书信息");c=getContentPane();(new BorderLayout());try{String strSQL="select book_name from book where book_count>borrowed_count";rs=(strSQL);while()){(1));}}catch(SQLException sqle){}catch(Exception ex){}(TipLabel,;(bb,;yes=new JButton("确定");exit=new JButton("退出");(this);(this);(yes);(exit);(panel1,;setVisible(true);}public void actionPerformed(ActionEvent e) {if()==exit){();}else if()==yes){try{String strSQL="select borrowed_count from book where book_name='"+()+"'";rs=(strSQL);if(!()){(null,"书库里没有你要删除的书");}else{String strSql="delete from book where book_name='"+()+"'and borrowed_count=0";();int count=(1);if(!(count==0)){(null,"此书还有学生没有还,不可删除");}else if(strSql)){(null,"删除成功");();();}else{(null,"删除失败");();();}}}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import class book_modify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel("输入书名点确定,将调出此书的相关信息");JLabel book_name_label,author_label,press_label,press_date_label,price_label;JTextField book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Container c;JButton clear,yes,update,exit;public book_modify(){super("修改图书信息");c=getContentPane();(new BorderLayout());panel3=new JPanel();(TipLabel);(panel3,;book_name_label=new JLabel("名称",; author_label=new JLabel("作者",;press_label=new JLabel("出版社",;press_date_label=new JLabel("出版日期",; price_label=new JLabel("价格",;book_name_TextField=new JTextField(15); author_TextField=new JTextField(15); press_TextField=new JTextField(15); press_date_TextField=new JTextField(15); price_TextField=new JTextField(15); panel1=new JPanel();(new GridLayout(6,2));(book_name_label);(book_name_TextField);(author_label);(author_TextField);(press_label);(press_TextField);(press_date_label);(press_date_TextField);(price_label);(price_TextField);panel2=new JPanel();(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");exit=new JButton("退出");(clear);(yes);(update);(exit);(this);(this);(this);(this);(false);(panel1,;(panel2,;setVisible(true);}public void actionPerformed(ActionEvent e) {if()==exit){();;}else if()==clear){("");("");("");("");("");}else if()==yes){try{String strSQL="select * from book where book_name='"+().trim()+"'";rs=(strSQL);while()){("book_name"));("author"));("press"));("press_date"));("price"));}(true);}catch(NullPointerException upe){}catch(Exception es){}}else if()==update){try{String strSQL="update book set book_name='"+().trim()+"',press='"+().trim()+"',author='"+().trim()+"',press_date='"+().trim()+"',price='"+().trim()+"' where book_name='"+().trim()+"'";if(strSQL)){();(null,"更新图书成功");}else {(null,"更新图书失败");}();}catch(Exception sqle){}}}}package library;import class bookborrow extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel borrowname,bookname,borrowdate,returndate,is_return_label;JTextField borrowdateField,returndateField,is_return;JButton clear,yes,cancel;JComboBox borrownameBox=new JComboBox();JComboBox booknameBox=new JComboBox();public bookborrow(){super("书籍出借");c=getContentPane();(new BorderLayout());Calendar cal = ();int year,month,day;quals("")){(null, "对不起,没有读者借阅");}else if().equals("")){(null, "对不起,现在书库没有书");}else {try{rim();SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");Date dateStart=(startDate);Calendar cd=();(dateStart);, 2);String returnDate=());String strSQL="insert into borrow(student_name,book_name,borrow_date,return_date,is_returned) values('"+()+"','"+()+"','"+().trim()+"','"+returnDate+"','"+().trim()+"')";if(strSQL)){(null, "借阅完成");strSQL = "update reader set borrow_count=borrow_count+1 where student_name='"+()+"'";(strSQL);strSQL="update book set borrowed_count=borrowed_count+1 where book_name='"+()+"'";(strSQL);();();}else{(null, "借阅失败");();();}}catch(Exception se){} }}}}package library;import .*;import .*;import class bookborrowlist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField booknamet,studentnamet;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public bookborrowlist(){super("借阅列表");c=getContentPane();(new BorderLayout());bookname=new JLabel("书名",;studentname=new JLabel("人名",;booknamet=new JTextField(15);studentnamet=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");(this);(this);Box box1=();(studentname);(studentnamet);(search);Box box2=();(bookname);(booknamet);(exit);Box boxH=();(box1);(box2);());panel1=new JPanel();(boxH);panel2=new JPanel();String []name={"读者","书名","借阅时间","应还时间","是否归还"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);(new Dimension(400,80));JScrollPane s=new JScrollPane(table);(s);(panel1,;(panel2,;}public void actionPerformed(ActionEvent e){if()==exit){();();}else if()==search){String strSQL="select student_name,book_name,borrow_date,return_date,is_returned from borrow";String strSql=null;if().trim().equals("")&&().trim().equals("")){strSql=strSQL;}else if().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"+().trim()+"'";}else if().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+().trim()+"'and book_name='"+().trim()+"'";(null, "你借的书还还有7天超期"); }try{int rowCount=()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){(j);(j);j=j-1;}rs=(strSql);while()){Vector insertRow=new Vector();(1));(2));(3));(4));(5));(insertRow);}();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import .*;import .*;import class bookborrowModify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookborrowModify(){super("修改图书出借信息");c=getContentPane();(new BorderLayout());panel3=new JPanel();(tiplabel);(panel3,;borrowlabel=new JLabel("借阅者姓名",;namelabel=new JLabel("书名",;borrowdate=new JLabel("借书日期",;borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();(new GridLayout(3,2));(borrowlabel); (borrowField); (namelabel); (nameField); (borrowdate); (dateField);(panel1,;panel2=new JPanel(); (new GridLayout(1,4)); clear=new JButton("清空"); yes=new JButton("确定"); update=new JButton("更新"); cancel=new JButton("取消"); (this);(this);(this);(this);(clear);(yes);(update);(cancel);(panel2,;setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e){if()==clear){("");("");("");}else if()==cancel){();}else if()==yes){try{String strSQL="select student_name,book_name,borrow_date from borrow where student_name='"+().trim()+"'and book_name='"+().trim()+"'";rs=(strSQL);if(!()){(null,"此学生没有借过书或者没有此书");}else{(1));(2));(3));(true);}}catch(Exception ex){}}else if()==update){String strSQL="update borrow set borrow_date='"+().trim()+"' where student_name='"+().trim()+"'and book_name='"+().trim()+"'";if(strSQL)){(null,"更新成功");();();}else{(null,"更新失败");();();}}}}package library;import .*;import .*;import class booklist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2,panel3;JLabel bookname,authorname,press; JTextField booknamet,authornamet,presst; JButton search,exit;JTable table=null; DefaultTableModel defaultModel=null; public booklist(){super("书籍信息查询");c=getContentPane();(new BorderLayout());bookname=new JLabel("书名",;authorname=new JLabel("作者",;press=new JLabel("出版社",;booknamet=new JTextField(15);authornamet=new JTextField(15);presst=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");(this);(this);panel1=new JPanel();(bookname);(booknamet);(authorname);(authornamet);panel2=new JPanel();(press);(presst);(search);(exit);String []name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel3=new JPanel();(s);(panel1,;(panel2,;(panel3,;}public void actionPerformed(ActionEvent e){if()==exit){();();}else if()==search){String strSQL="select book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_address from book";String strSql=null;if().trim().equals("")&&().trim().equals("")&&().trim().equals("")){strSql=strSQL;}else if().trim().equals("")&&().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_address from book where press='"+().trim()+"'";}else if().trim().equals("")&&().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_address from book where book_name='"+().trim()+"'";}else if().trim().equals("")&&().trim().equals("")){strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_address from book where author='"+().trim()+"'";}else{strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_c ount-borrowed_count,store_address from book where book_name='"+().trim()+"'and author='"+().trim()+"'and press='"+().trim()+"'";}try{int rowCount=()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){(j);(j);j=j-1;}rs=(strSql);while()){Vector insertRow=new Vector();(1));(2));(3));(4));(5));(6));(7));(8));(9));(10));(insertRow);}();}catch(SQLException sqle){}catch(Exception ex){}}}}package library;import .*;import .*;import class bookreturn extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;Container c;JLabel namelabel,booklabel,returndatelabel;JTextField returnField;JButton clear,yes,cancel;JComboBox bookname=new JComboBox();JComboBox readername=new JComboBox();public bookreturn(){super("图书还入");c=getContentPane();(new BorderLayout());Calendar cal = ();sdf = new SimpleDateFormat("yyyy-MM-dd");String cdate = ());namelabel=new JLabel("还书者姓名",;booklabel =new JLabel("书名",;returndatelabel=new JLabel("日期",;returnField=new JTextField(15);(cdate);try{String s="";String strSQL="select student_name from reader where borrow_count!=0";rs=(strSQL);while()){(1));}}catch(SQLException sqle){}catch(Exception ex){}try{String s="";String strSQL="select book_name from borrow where is_returned='否'";rs=(strSQL);while()){(1));}}catch(SQLException sqle){}catch(Exception ex){}panel1=new JPanel();(new GridLayout(3,2)); (namelabel);(readername);(booklabel);(bookname);(returndatelabel);(returnField);(panel1,;panel2=new JPanel();(new GridLayout(1,3));clear=new JButton("清除");yes=new JButton("确定");cancel=new JButton("取消"); (this);(this);(this);(clear);(yes);(cancel);(panel2,;setVisible(true);setSize(300,200);}public void actionPerformed(ActionEvent e) {if()==cancel){();}else if()==clear){("");}else if()==yes){if().equals("")){(null,"没有读者借书");}else if().equals("")){(null,"图书馆没有借过书");}else{try{String strSQL="update borrow set act_returned ='"+().trim()+"',is_returned='是' where student_name='"+()+"' and book_name='"+()+"'";if(strSQL)){(null,"还书完成");strSQL="update reader set borrow_count=borrow_count-1 where student_name='"+()+"'";(strSQL);strSQL="update book set borrowed_count=borrowed_count-1 where book_name='"+()+"'";(strSQL);();();}else{(null,"还书失败");();();}}catch(Exception se){}};import .*;import class bookreturnModify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入还书者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookreturnModify(){super("修改图书还入信息");c=getContentPane();(new BorderLayout());panel3=new JPanel();(tiplabel);(panel3,;borrowlabel=new JLabel("还书者姓名",;namelabel=new JLabel("书名",;borrowdate=new JLabel("还书日期",;borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();(new GridLayout(3,2));(borrowlabel);(borrowField);(namelabel);(nameField);(borrowdate);(dateField);(panel1,;panel2=new JPanel();(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");cancel=new JButton("取消");(this);(this);(this);(this);(clear);(yes);(update);(cancel);(panel2,;setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e) {if()==clear){("");("");("");}else if()==cancel){();}else if()==yes){try{String strSQL="select student_name,book_name,act_returned from borrow where student_name='"+().trim()+"'and book_name='"+().trim()+"'";rs=(strSQL);if(!()){(null,"此学生没有借过书");}else{(1));(2));(3));(true);}}catch(Exception ex){}}else if()==update){String strSQL="update borrow set return_date='"+().trim()+"' where student_name='"+().trim()+"'and book_name='"+().trim()+"'";if(strSQL)){(null,"更新成功");();();}else{(null,"更新失败");();();}}}}package library;import .*;import .*;import class MainWindow extends JFrame implements ActionListener{ JPanel panel1;Container c;JMenuBar MenuB;JMenu system,book,borrow,retu,info,usermag;JMenu student;quals("系统管理员")){(true);(true);(true);(true);(true);(true);(true);}else if().equals("书籍管理员")) {(false);(true);(false);(false);(true);(false);(true);}else if().equals("借阅管理员")) {(false);(false);。
基于java的图书管理系统源代码
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_add extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,book_name_label,author_label,press_label,press_date_label,price_label,book_num_label,borrowed_num_label,a ddress;JTextField book_id_TextField,book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField,book_num_TextField,borrowed_count;JComboBox addresst;Container c;JButton clear,add,exit;public book_add(){super("添加图书信息");c=getContentPane();c.setLayout(new BorderLayout());book_id_label=new JLabel("编号",JLabel.CENTER);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER); price_label=new JLabel("价格",JLabel.CENTER);book_num_label=new JLabel("库存数",JLabel.CENTER); borrowed_num_label=new JLabel("已借阅数",JLabel.CENTER); address=new JLabel("藏书地址",JLabel.CENTER);book_id_TextField=new JTextField(15);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);book_num_TextField=new JTextField(15);borrowed_count=new JTextField(15);borrowed_count.setText("0");addresst=new JComboBox();addresst.addItem("扬子津图书馆");addresst.addItem("荷花池图书馆");addresst.addItem("瘦西湖图书馆");addresst.addItem("淮海路图书馆");panel1=new JPanel();panel1.setLayout(new GridLayout(9,2));panel1.add(book_id_label);panel1.add(book_id_TextField);panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel1.add(book_num_label);panel1.add(book_num_TextField);panel1.add(borrowed_num_label);panel1.add(borrowed_count);panel1.add(address);panel1.add(addresst);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");clear.addActionListener(this);add=new JButton("添加");add.addActionListener(this);exit=new JButton("退出");exit.addActionListener(this);panel2.add(clear);panel2.add(add);panel2.add(exit);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==clear){book_id_TextField.setText("");book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");book_num_TextField.setText("");}else if(e.getSource()==add){if(book_id_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书号不能为空");}else if(book_name_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "书名不能为空");}else if(author_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "作者不能为空");}else if(press_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版社不能为空");}else if(press_date_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "出版日期不能为空");}else if(price_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "价格不能为空");}else if(book_num_TextField.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "库存不能为空");}else if(borrowed_count.getText().trim().equals("")){JOptionPane.showMessageDialog(null, "借阅数不能为空");}else {try{String strSQL="insert into book(book_id,book_name,press,author,press_date,price,book_count,borrowed_count, store_address) values('"+book_id_TextField.getText().trim()+"','"+book_name_TextField.getText().trim()+"','"+press_TextField.getText().trim()+"','"+author_TextField.getText().trim()+"','"+press_date_TextField.getText().trim()+"','"+price_TextField.getText().trim()+"','"+book_num_TextField.getText().trim()+"','"+borrowed_count.getText().trim()+"','"+addresst.getSelectedItem()+"')";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"添加图书成功");}else{JOptionPane.showMessageDialog(null,"添加图书失败");this.dispose();}db.closeConnection();}catch(Exception ex){System.out.println(ex.toString());}}}}}package library;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;public class book_delete extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JLabel TipLabel=new JLabel("请选择要删除的书名",JLabel.CENTER);JComboBox bb=new JComboBox();JButton yes,exit;JPanel panel1=new JPanel();public book_delete(){super("删除图书信息");c=getContentPane();c.setLayout(new BorderLayout());try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){bb.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}c.add(TipLabel,BorderLayout.NORTH);c.add(bb,BorderLayout.CENTER);yes=new JButton("确定");exit=new JButton("退出");yes.addActionListener(this);exit.addActionListener(this);panel1.add(yes);panel1.add(exit);c.add(panel1,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select borrowed_count from book where book_name='"+bb.getSelectedItem()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"书库里没有你要删除的书");}else{String strSql="delete from book where book_name='"+bb.getSelectedItem()+"'and borrowed_count=0";rs.first();int count=rs.getInt(1);if(!(count==0)){JOptionPane.showMessageDialog(null,"此书还有学生没有还,不可删除");}else if(db.updateSql(strSql)){JOptionPane.showMessageDialog(null,"删除成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"删除失败");db.closeConnection();this.dispose();}}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}}}}package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_modify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel("输入书名点确定,将调出此书的相关信息");JLabel book_name_label,author_label,press_label,press_date_label,price_label;JTextField book_name_TextField,author_TextField,press_TextField,press_date_TextField,price_TextField;Container c;JButton clear,yes,update,exit;public book_modify(){super("修改图书信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(TipLabel);c.add(panel3,BorderLayout.NORTH);book_name_label=new JLabel("名称",JLabel.CENTER);author_label=new JLabel("作者",JLabel.CENTER);press_label=new JLabel("出版社",JLabel.CENTER);press_date_label=new JLabel("出版日期",JLabel.CENTER);price_label=new JLabel("价格",JLabel.CENTER);book_name_TextField=new JTextField(15);author_TextField=new JTextField(15);press_TextField=new JTextField(15);press_date_TextField=new JTextField(15);price_TextField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(6,2));panel1.add(book_name_label);panel1.add(book_name_TextField);panel1.add(author_label);panel1.add(author_TextField);panel1.add(press_label);panel1.add(press_TextField);panel1.add(press_date_label);panel1.add(press_date_TextField);panel1.add(price_label);panel1.add(price_TextField);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");exit=new JButton("退出");panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(exit);clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);exit.addActionListener(this);update.setEnabled(false);c.add(panel1,BorderLayout.CENTER);c.add(panel2,BorderLayout.SOUTH);setVisible(true);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){this.dispose();;}else if(e.getSource()==clear){book_name_TextField.setText("");author_TextField.setText("");press_TextField.setText("");press_date_TextField.setText("");price_TextField.setText("");}else if(e.getSource()==yes){try{String strSQL="select * from book where book_name='"+book_name_TextField.getText().trim()+"'";rs=db.getResult(strSQL);while(rs.next()){book_name_TextField.setText(rs.getString("book_name"));author_TextField.setText(rs.getString("author"));press_TextField.setText(rs.getString("press"));press_date_TextField.setText(rs.getString("press_date"));price_TextField.setText(rs.getString("price"));}update.setEnabled(true);}catch(NullPointerException upe){System.out.println(upe.toString());}catch(Exception es){System.out.println(es.toString());}}else if(e.getSource()==update){try{String strSQL="update book set book_name='"+book_name_TextField.getText().trim()+"',press='"+press_TextField.getText().trim()+"',author='"+author_TextField.getText().trim()+"',press_date='"+press_date_TextField.getText().trim()+"',price='"+price_TextField.getText().trim()+"' where book_name='"+book_name_TextField.getText().trim()+"'";if(db.updateSql(strSQL)){this.dispose();JOptionPane.showMessageDialog(null,"更新图书成功");}else {JOptionPane.showMessageDialog(null,"更新图书失败");}db.closeConnection();}catch(Exception sqle){System.out.println(sqle.toString());}}}}package library;import java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class bookborrow extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel borrowname,bookname,borrowdate,returndate,is_return_label;JTextField borrowdateField,returndateField,is_return;JButton clear,yes,cancel;JComboBox borrownameBox=new JComboBox();JComboBox booknameBox=new JComboBox();public bookborrow(){super("书籍出借");c=getContentPane();c.setLayout(new BorderLayout());Calendar cal = Calendar.getInstance();int year,month,day;// year=cal.get(Calendar.YEAR);// month=cal.get(Calendar.MONTH)+3;//从0开始的// day=cal.get(Calendar.DAY_OF_MONTH);// java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// String cdate = sdf.format(cal.getTime());// String da=Integer.toString(year)+"-0"+Integer.toString(month)+"-"+Integer.toString(day);borrowname=new JLabel("借阅者姓名",JLabel.CENTER);bookname=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);// returndate=new JLabel("应还日期",JLabel.CENTER);is_return_label=new JLabel("是否归还",JLabel.CENTER);borrowdateField=new JTextField(15);// borrowdateField.setText(cdate);// returndateField=new JTextField(15);// returndateField.setText(da);is_return=new JTextField(15);is_return.setText("否");try{String strSql="select student_name from reader ";rs=db.getResult(strSql);while(rs.next()){borrownameBox.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}try{String strSQL="select book_name from book where book_count>borrowed_count";rs=db.getResult(strSQL);while(rs.next()){booknameBox.addItem(rs.getString(1));}}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}panel1=new JPanel();panel1.setLayout(new GridLayout(5,2));panel1.add(borrowname);panel1.add(borrownameBox);panel1.add(bookname);panel1.add(booknameBox);panel1.add(borrowdate);panel1.add(borrowdateField);// panel1.add(returndate);// panel1.add(returndateField);panel1.add(is_return_label);panel1.add(is_return);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));clear=new JButton("清空");yes=new JButton("确定");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(300,300);}public void actionPerformed(ActionEvent e){if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==clear){borrowdateField.setText("");// returndateField.setText("");is_return.setText("");}else if(e.getSource()==yes){if(borrownameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,没有读者借阅");}else if(booknameBox.getSelectedItem().equals("")){JOptionPane.showMessageDialog(null, "对不起,现在书库没有书");}else {try{//系统计算归还日期//获取输入的借阅日期,自动加两个月String startDate=borrowdateField.getText().trim();SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");Date dateStart=format.parse(startDate);Calendar cd=Calendar.getInstance();cd.setTime(dateStart);cd.add(Calendar.MONTH, 2);String returnDate=format.format(cd.getTime());String strSQL="insert into borrow(student_name,book_name,borrow_date,return_date,is_returned) values('"+borrownameBox.getSelectedItem()+"','"+booknameBox.getSelectedItem()+"','"+borrowdateField.getText().trim()+"','"+returnDate+"','"+is_return.getText().trim()+"')";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null, "借阅完成");strSQL = "update reader set borrow_count=borrow_count+1 where student_name='"+borrownameBox.getSelectedItem()+"'";db.updateSql(strSQL);strSQL="update book set borrowed_count=borrowed_count+1 where book_name='"+booknameBox.getSelectedItem()+"'";db.updateSql(strSQL);db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null, "借阅失败");db.closeConnection();this.dispose();}}catch(Exception se){System.out.println(se.toString());}}}}}package library;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;public class bookborrowlist extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField booknamet,studentnamet;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public bookborrowlist(){super("借阅列表");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);studentname=new JLabel("人名",JLabel.CENTER);booknamet=new JTextField(15);studentnamet=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);Box box1=Box.createHorizontalBox();box1.add(studentname);box1.add(studentnamet);box1.add(search);Box box2=Box.createHorizontalBox();box2.add(bookname);box2.add(booknamet);box2.add(exit);Box boxH=Box.createVerticalBox();boxH.add(box1);boxH.add(box2);boxH.add(Box.createVerticalGlue());panel1=new JPanel();panel1.add(boxH);panel2=new JPanel();String []name={"读者","书名","借阅时间","应还时间","是否归还"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel2.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select student_name,book_name,borrow_date,return_date,is_returned from borrow";String strSql=null;if(studentnamet.getText().trim().equals("")&&booknamet.getText().trim().equals( "")){strSql=strSQL;}else if(studentnamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"+booknamet.getText().trim()+"'";}else if(booknamet.getText().trim().equals("")){strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'";}else{strSql="selectstudent_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"+studentnamet.getText().trim()+"'and book_name='"+booknamet.getText().trim()+"'";JOptionPane.showMessageDialog(null, "你借的书还还有7天超期");}try{int rowCount=defaultModel.getRowCount()-1;int j=rowCount;for(int i=0;i<=rowCount;i++){defaultModel.removeRow(j);defaultModel.setRowCount(j);j=j-1;}rs=db.getResult(strSql);while(rs.next()){Vector insertRow=new Vector();insertRow.addElement(rs.getString(1));insertRow.addElement(rs.getString(2));insertRow.addElement(rs.getString(3));insertRow.addElement(rs.getString(4));insertRow.addElement(rs.getString(5));defaultModel.addRow(insertRow);}table.revalidate();}catch(SQLException sqle){System.out.println(sqle.toString());}catch(Exception ex){System.out.println(ex.toString());}}}}package library;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;public class bookborrowModify extends JFrame implements ActionListener{ DataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;Container c;JLabel tiplabel=new JLabel("输入借阅者姓名和书名单击确定,将调出此书的相关信息");JLabel borrowlabel,namelabel,borrowdate;JTextField borrowField,nameField,dateField;JButton clear,yes,update,cancel;public bookborrowModify(){super("修改图书出借信息");c=getContentPane();c.setLayout(new BorderLayout());panel3=new JPanel();panel3.add(tiplabel);c.add(panel3,BorderLayout.NORTH);borrowlabel=new JLabel("借阅者姓名",JLabel.CENTER);namelabel=new JLabel("书名",JLabel.CENTER);borrowdate=new JLabel("借书日期",JLabel.CENTER);borrowField=new JTextField(15);nameField=new JTextField(15);dateField=new JTextField(15);panel1=new JPanel();panel1.setLayout(new GridLayout(3,2));panel1.add(borrowlabel);panel1.add(borrowField);panel1.add(namelabel);panel1.add(nameField);panel1.add(borrowdate);panel1.add(dateField);c.add(panel1,BorderLayout.CENTER);panel2=new JPanel();panel2.setLayout(new GridLayout(1,4));clear=new JButton("清空");yes=new JButton("确定");update=new JButton("更新");cancel=new JButton("取消");clear.addActionListener(this);yes.addActionListener(this);update.addActionListener(this);cancel.addActionListener(this);panel2.add(clear);panel2.add(yes);panel2.add(update);panel2.add(cancel);c.add(panel2,BorderLayout.SOUTH);setVisible(true);setSize(400,200);}public void actionPerformed(ActionEvent e){if(e.getSource()==clear){borrowField.setText("");nameField.setText("");dateField.setText("");}else if(e.getSource()==cancel){this.dispose();}else if(e.getSource()==yes){try{String strSQL="select student_name,book_name,borrow_date from borrow where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";rs=db.getResult(strSQL);if(!rs.first()){JOptionPane.showMessageDialog(null,"此学生没有借过书或者没有此书");}else{borrowField.setText(rs.getString(1));nameField.setText(rs.getString(2));dateField.setText(rs.getString(3));update.setEnabled(true);}}catch(Exception ex){System.out.println(ex.toString());}}else if(e.getSource()==update){String strSQL="update borrow set borrow_date='"+dateField.getText().trim()+"' where student_name='"+borrowField.getText().trim()+"'and book_name='"+nameField.getText().trim()+"'";if(db.updateSql(strSQL)){JOptionPane.showMessageDialog(null,"更新成功");db.closeConnection();this.dispose();}else{JOptionPane.showMessageDialog(null,"更新失败");db.closeConnection();this.dispose();}}}}package library;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;public class booklist extends JFrame implements ActionListener{DataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2,panel3;JLabel bookname,authorname,press;JTextField booknamet,authornamet,presst;JButton search,exit;JTable table=null;DefaultTableModel defaultModel=null;public booklist(){super("书籍信息查询");c=getContentPane();c.setLayout(new BorderLayout());bookname=new JLabel("书名",JLabel.CENTER);authorname=new JLabel("作者",JLabel.CENTER);press=new JLabel("出版社",JLabel.CENTER);booknamet=new JTextField(15);authornamet=new JTextField(15);presst=new JTextField(15);search=new JButton("查询");exit=new JButton("退出");search.addActionListener(this);exit.addActionListener(this);panel1=new JPanel();panel1.add(bookname);panel1.add(booknamet);panel1.add(authorname);panel1.add(authornamet);panel2=new JPanel();panel2.add(press);panel2.add(presst);panel2.add(search);panel2.add(exit);String []name={"书号","书名","出版社","作者","出版日期","价格","图书数目","已借数目","剩余数目","藏书地址"};String [][]data=new String[0][0];defaultModel=new DefaultTableModel(data,name);table=new JTable(defaultModel);table.setPreferredScrollableViewportSize(new Dimension(400,80));JScrollPane s=new JScrollPane(table);panel3=new JPanel();panel3.add(s);c.add(panel1,BorderLayout.NORTH);c.add(panel2,BorderLayout.CENTER);c.add(panel3,BorderLayout.SOUTH);}public void actionPerformed(ActionEvent e){if(e.getSource()==exit){db.closeConnection();this.dispose();}else if(e.getSource()==search){String strSQL="select book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book";String strSql=null;if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals(" ")&&presst.getText().trim().equals("")){strSql=strSQL;}elseif(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")) {strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where press='"+presst.getText().trim()+"'";}elseif(authornamet.getText().trim().equals("")&&presst.getText().trim().equals("")) {strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_ count-borrowed_count,store_address from book where book_name='"+booknamet.getText().trim()+"'";}elseif(booknamet.getText().trim().equals("")&&presst.getText().trim().equals("")) {strSql="selectbook_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_。
java项目开发实例图书信息管理系统开发及源码
图书信息管理系统一、系统功能概述:根据图书信息管理系统的特点,可以将本系统分为2大功能模块,分别为:基础数据维护、系统数据维护。
本系统各个部分及其包括的具体功能模块如下图所示:二、数据库设计:三、系统源代码:ewInstance();conn = (dbUrl, dbUser, dbPwd);"数据库连接成功!");}elsereturn;} catch (Exception ee) {();}}xecuteQuery(sql);} catch (SQLException e) {();return null;} finally {}}xecuteUpdate(sql);} catch (SQLException e) {quals("[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE 语句与 COLUMN REFERENCE 约束 'FK_TB_BORRO_REFERENCE_TB_BOOKI' 冲突。
该冲突发生于数据库'db_library',表 'tb_borrow', column 'bookISBN'。
"))return -1;} finally {}}etLayout(borderLayout);setIconifiable(true); dd(panel);final JLabel label_2 = new JLabel();("图书编号:");(label_2);ISBN = new JTextField("请输入13位书号",13);(new MyDocument(13)); dd(panel_1, ;final FlowLayout flowLayout = new FlowLayout();(2);(30);;(flowLayout);buttonadd= new JButton();(new addBookActionListener());("添加");(buttonadd);buttonclose = new JButton();(new CloseActionListener());("关闭");(buttonclose);final JLabel label_5 = new JLabel();ImageIcon bookAddIcon=("");(bookAddIcon);(new Dimension(400, 80));(new LineBorder, 1, false));getContentPane().add(label_5, ;("新书定购(LOGO图片)");setVisible(true); rim()).isEmpty()){ (null, "添加书号重复!");return;}}}class ISBNkeyListener extends KeyAdapter {public void keyPressed(final KeyEvent e) {if () == 13){();}}}class CloseActionListener implements ActionListener { ength()==0){(null, "书号文本框不可以为空");return;}if().length()!=13){(null, "书号文本框输入位数为13位");return;}if().length()==0){(null, "图书名称文本框不可以为空");return;}if().length()==0){(null, "作者文本框不可以为空");return;}if().length()==0){(null, "出版日期文本框不可以为空");return;}if().length()==0){(null, "单价文本框不可以为空");return;}String ISBNs=().trim();rim();String bookNames=().trim();String writers=().trim();String publishers=(String)().trim();String pubDates=().trim();String prices=().trim();int i=(ISBNs,bookTypes, bookNames, writers, translators, publishers, if(i==1){(null, "添加成功");doDefaultCloseAction();}}}class NumberListener extends KeyAdapter {public void keyTyped(KeyEvent e) {String numStr="09."+(char)8;if())<0){();}}}}et()));results[i][1]=booktypename;results[i][2]=();results[i][3]=();results[i][4]=();results[i][5]=();results[i][6]=();results[i][7]=();}return results;}public BookModiAndDelIFrame() {super();final BorderLayout borderLayout = new BorderLayout();getContentPane().setLayout(borderLayout);setIconifiable(true);setClosable(true);setTitle("图书信息修改与删除");setBounds(100, 100, 640, 406);dd(panel_1, ;final FlowLayout flowLayout = new FlowLayout();(2);(30);;(flowLayout);final JButton button = new JButton();(new addBookActionListener());("修改");(button);final JButton button_2 = new JButton();(new ActionListener(){public void actionPerformed(final ActionEvent e) {String ISBNs=().trim();int i=(ISBNs);if(i==1){(null, "删除成功");Object[][] results=getFileStates());dd(headLogo, ;final JPanel panel_2 = new JPanel();final BorderLayout borderLayout_1 = new BorderLayout();(5);(borderLayout_1);(new EmptyBorder(5, 10, 5, 10));getContentPane().add(panel_2);final JScrollPane scrollPane = new JScrollPane();(scrollPane);Object[][] results=getFileStates());columnNames = new String[]{"图书编号", "图书类别", "图书名称", "作者", "译者", "出版商", "出版日期","价格"};table = new JTable(results,columnNames);;oString().trim();typeids = (selRow, 1).toString().trim();bookNames = (selRow, 2).toString().trim();writers = (selRow, 3).toString().trim();translators = (selRow, 4).toString().trim();publishers = (selRow, 5).toString().trim();dates = (selRow, 6).toString().trim();prices = (selRow, 7).toString().trim();(ISBNs);ength()==0){(null, "书号文本框不可以为空或则输入数字不可以大于13个");return;}if().length()!=13){(null, "书号文本框输入位数为13位");return;}if().length()==0){(null, "图书名称文本框不可以为空");return;}if().length()==0){(null, "作者文本框不可以为空");return;}if().length()==0){(null, "出版人文本框不可以为空");return;}ength()==0){(null, "出版日期文本框不可以为空");return;}if().length()==0){(null, "单价文本框不可以为空");return;}String ISBNs=().trim();rim();String bookNames=().trim();String writers=().trim();String publishers=().trim();String pubDates=().trim();String prices=().trim();int i=(ISBNs, bookTypes, bookNames, writers, translators, publishers, (pubDates), (prices));if(i==1){(null, "修改成功");Object[][] results=getFileStates());+(char)8;if())<0){();}}}}dd(panel, ;final JLabel label_4 = new JLabel();ImageIcon bookTypeAddIcon=("");(bookTypeAddIcon);(new Dimension(360, 80));("图书类别图片(400*80)");(label_4);final JPanel panel_3 = new JPanel();(new FlowLayout());getContentPane().add(panel_3, ;final JLabel label_1 = new JLabel();(new Dimension(20, 50));(label_1);final JLabel label_2 = new JLabel();(new Dimension(90, 20));("图书类别名称:");(label_2);bookTypeName = new JTextField();(new MyDocument(20));(30);(bookTypeName);final JButton button = new JButton();("保存");(new ActionListener(){public void actionPerformed(final ActionEvent e) {if().length()==0){(null, "图书类别文本框不可为空");return;}int i=().trim());if(i==1){(null, "添加成功!");doDefaultCloseAction();}else{(null, "图书类别名已存在,请重新输入!");}}});(button);final JButton buttonDel = new JButton();("关闭");(new ActionListener(){public void actionPerformed(final ActionEvent e) {doDefaultCloseAction();}});(buttonDel);setVisible(true);}class NumberListener extends KeyAdapter {public void keyTyped(KeyEvent e) {String numStr="09."+(char)8;if())<0){();}}}}dd(panel, ;final JLabel logoLabel = new JLabel();ImageIcon bookTypeModiAndDelIcon=("");(bookTypeModiAndDelIcon);(new Dimension(400, 80));("logo");(logoLabel);final JPanel panel_1 = new JPanel();getContentPane().add(panel_1);final JScrollPane scrollPane = new JScrollPane();(new Dimension(400, 130));(scrollPane);model=new DefaultTableModel();Object[][] results=getFileStates());(results,columnNames);table = new JTable();(model);(new TableListener());(table);final JPanel panel_2 = new JPanel();(panel_2);final GridLayout gridLayout = new GridLayout(0, 6);(5);(5);(gridLayout);(new Dimension(400, 26));final JLabel label = new JLabel();("类别编号:");(label);BookTypeId = new JTextField();(false);(BookTypeId);final JLabel label_1 = new JLabel();("类别名称:");(label_1);comboBox = new JComboBox();bookTypeModel= (DefaultComboBoxModel)();oString().trim());(selRow, 1).toString().trim());}}class ButtonAddListener implements ActionListener{public void actionPerformed(ActionEvent e){Object selectedItem = ();int i=().trim(),());if(i==1){(null, "修改成功");Object[][] results=getFileStates());(results,columnNames);(model);}}}class ButtonDelListener implements ActionListener{public void actionPerformed(ActionEvent e){int i=().trim());if(i==1){(null, "删除成功");Object[][] results=getFileStates());(results,columnNames);(model);}}}class CloseActionListener implements ActionListener { etLayout(borderLayout);setTitle("图书馆管理系统登录");setBounds(100, 100, 285, 194);final JPanel panel = new JPanel();(new BorderLayout());(new EmptyBorder(0, 0, 0, 0));getContentPane().add(panel);final JPanel panel_2 = new JPanel();final GridLayout gridLayout = new GridLayout(0, 2);(5);(20);(gridLayout);(panel_2);final JLabel label = new JLabel();;(new Dimension(0, 0));(new Dimension(0, 0));(label);("用户名:");username = new JTextField(20);(new Dimension(0, 0));(username);final JLabel label_1 = new JLabel();;(label_1);("密码:");password = new JPasswordField(20);(new MyDocument(6));('*');etSystemLookAndFeelClassName());new LoginIFrame();dd(toolBar, ;final JLabel label = new JLabel();(0, 0, 0, 0);(null); etSize();().getSize());("<html><img width=" + + " height="+ + " src='"+ ().getResource("/")+ "'></html>");}});(label,new Integer);getContentPane().add(DESKTOP_PANE);}/*** 创建工具栏** @return JToolBar*/private JToolBar createToolBar() { etLayout(new GridBagLayout());setBounds(100, 100, 300, 228);final JLabel label_4 = new JLabel();(new Font("", , 14));;("<html>注:每个<b>操作员</b>只能修改自己的密码。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
j a v a项目开发实例图书信息管理系统开发及源码集团文件发布号:(9816-UATWW-MWUB-WUNN-INNUL-DQQTY-图书信息管理系统一、系统功能概述:根据图书信息管理系统的特点,可以将本系统分为2大功能模块,分别为:基础数据维护、系统数据维护。
本系统各个部分及其包括的具体功能模块如下图所示:二、数据库设计:图书信息表:图书类别表:用户信息表:读者信息表:三、系统源代码:ewInstance();conn = (dbUrl, dbUser, dbPwd);"数据库连接成功!");}elsereturn;} catch (Exception ee) {();}}xecuteQuery(sql);} catch (SQLException e) {();return null;} finally {}}xecuteUpdate(sql);} catch (SQLException e) {quals("[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE 语句与 COLUMN REFERENCE 约束'FK_TB_BORRO_REFERENCE_TB_BOOKI' 冲突。
该冲突发生于数据库'db_library',表 'tb_borrow', column 'bookISBN'。
"))return -1;} finally {}}etLayout(borderLayout);setIconifiable(true); dd(panel);final JLabel label_2 = new JLabel();("图书编号:");(label_2);ISBN = new JTextField("请输入13位书号",13);(new MyDocument(13)); dd(panel_1, ;final FlowLayout flowLayout = new FlowLayout();(2);(30);;(flowLayout);buttonadd= new JButton();(new addBookActionListener()); ("添加");(buttonadd);buttonclose = new JButton();(new CloseActionListener());("关闭");(buttonclose);final JLabel label_5 = new JLabel(); ImageIcon bookAddIcon=(""); (bookAddIcon);(new Dimension(400, 80));(new LineBorder, 1, false)); getContentPane().add(label_5, ; ("新书定购(LOGO图片)");setVisible(true);rim()).isEmpty()){(null, "添加书号重复!");return;}}}class ISBNkeyListener extends KeyAdapter {public void keyPressed(final KeyEvent e) {if () == 13){();}}}class CloseActionListener implements ActionListener { ength()==0){(null, "书号文本框不可以为空");return;}if().length()!=13){(null, "书号文本框输入位数为13位");return;}if().length()==0){(null, "图书名称文本框不可以为空");return;}if().length()==0){(null, "作者文本框不可以为空");return;}if().length()==0){(null, "出版日期文本框不可以为空");return;}if().length()==0){(null, "单价文本框不可以为空");return;}String ISBNs=().trim();rim();String bookNames=().trim();String writers=().trim();String publishers=(String)().trim();String pubDates=().trim();String prices=().trim();int i=(ISBNs,bookTypes, bookNames, writers, translators, publishers, if(i==1){(null, "添加成功");doDefaultCloseAction();}}}class NumberListener extends KeyAdapter { public void keyTyped(KeyEvent e) {String numStr="09."+(char)8;if())<0){();}}}}et()));results[i][1]=booktypename;results[i][2]=();results[i][3]=();results[i][4]=();results[i][5]=();results[i][6]=();results[i][7]=();}return results;}public BookModiAndDelIFrame() {super();final BorderLayout borderLayout = new BorderLayout();getContentPane().setLayout(borderLayout);setIconifiable(true);setClosable(true);setTitle("图书信息修改与删除");setBounds(100, 100, 640, 406);dd(panel_1, ;final FlowLayout flowLayout = new FlowLayout();(2);(30);;(flowLayout);final JButton button = new JButton();(new addBookActionListener());("修改");(button);final JButton button_2 = new JButton();(new ActionListener(){public void actionPerformed(final ActionEvent e) {String ISBNs=().trim();int i=(ISBNs);if(i==1){(null, "删除成功");Object[][] results=getFileStates());dd(headLogo, ;final JPanel panel_2 = new JPanel();final BorderLayout borderLayout_1 = new BorderLayout();(5);(borderLayout_1);(new EmptyBorder(5, 10, 5, 10));getContentPane().add(panel_2);final JScrollPane scrollPane = new JScrollPane();(scrollPane);Object[][] results=getFileStates());columnNames = new String[]{"图书编号", "图书类别", "图书名称", "作者", "译者", "出版商", "出版日期","价格"};table = new JTable(results,columnNames);;oString().trim();typeids = (selRow, 1).toString().trim();bookNames = (selRow, 2).toString().trim();writers = (selRow, 3).toString().trim();translators = (selRow, 4).toString().trim();publishers = (selRow, 5).toString().trim();dates = (selRow, 6).toString().trim();prices = (selRow, 7).toString().trim();(ISBNs);ength()==0){(null, "书号文本框不可以为空或则输入数字不可以大于13个");return;}if().length()!=13){(null, "书号文本框输入位数为13位");return;}if().length()==0){(null, "图书名称文本框不可以为空");return;}if().length()==0){(null, "作者文本框不可以为空");return;}if().length()==0){(null, "出版人文本框不可以为空");}ength()==0){(null, "出版日期文本框不可以为空");return;}if().length()==0){(null, "单价文本框不可以为空");return;}String ISBNs=().trim();rim();String bookNames=().trim();String writers=().trim();String publishers=().trim();String pubDates=().trim();String prices=().trim();int i=(ISBNs, bookTypes, bookNames, writers, translators, publishers, (pubDates), (prices));if(i==1){(null, "修改成功");Object[][] results=getFileStates());+(char)8;();}}}}dd(panel, ;final JLabel label_4 = new JLabel();ImageIcon bookTypeAddIcon=("");(bookTypeAddIcon);(new Dimension(360, 80));("图书类别图片(400*80)");(label_4);final JPanel panel_3 = new JPanel();(new FlowLayout());getContentPane().add(panel_3, ;final JLabel label_1 = new JLabel();(new Dimension(20, 50));(label_1);final JLabel label_2 = new JLabel();(new Dimension(90, 20));("图书类别名称:");(label_2);(new MyDocument(20));(30);(bookTypeName);final JButton button = new JButton();("保存");(new ActionListener(){public void actionPerformed(final ActionEvent e) { if().length()==0){(null, "图书类别文本框不可为空");return;}int i=().trim());if(i==1){(null, "添加成功!");doDefaultCloseAction();}else{(null, "图书类别名已存在,请重新输入!");}}});(button);final JButton buttonDel = new JButton();(new ActionListener(){public void actionPerformed(final ActionEvent e) {doDefaultCloseAction();}});(buttonDel);setVisible(true);}class NumberListener extends KeyAdapter {public void keyTyped(KeyEvent e) {String numStr="09."+(char)8;if())<0){();}}}}dd(panel, ;final JLabel logoLabel = new JLabel();ImageIcon bookTypeModiAndDelIcon=("");(bookTypeModiAndDelIcon);(new Dimension(400, 80));(logoLabel);final JPanel panel_1 = new JPanel(); getContentPane().add(panel_1);final JScrollPane scrollPane = new JScrollPane(); (new Dimension(400, 130));(scrollPane);model=new DefaultTableModel();Object[][] results=getFileStates());(results,columnNames);table = new JTable();(model);(new TableListener());(table);final JPanel panel_2 = new JPanel();(panel_2);final GridLayout gridLayout = new GridLayout(0, 6);(5);(5);(gridLayout);(new Dimension(400, 26));final JLabel label = new JLabel();("类别编号:");BookTypeId = new JTextField();(false);(BookTypeId);final JLabel label_1 = new JLabel();("类别名称:");(label_1);comboBox = new JComboBox();bookTypeModel= (DefaultComboBoxModel)();oString().trim());(selRow, 1).toString().trim());}}class ButtonAddListener implements ActionListener{ public void actionPerformed(ActionEvent e){Object selectedItem = ();int i=().trim(),());if(i==1){(null, "修改成功");Object[][] results=getFileStates());(results,columnNames);(model);}}class ButtonDelListener implements ActionListener{ public void actionPerformed(ActionEvent e){int i=().trim());if(i==1){(null, "删除成功");Object[][] results=getFileStates());(results,columnNames);(model);}}}class CloseActionListener implements ActionListener { etLayout(borderLayout);setTitle("图书馆管理系统登录");setBounds(100, 100, 285, 194);final JPanel panel = new JPanel();(new BorderLayout());(new EmptyBorder(0, 0, 0, 0));getContentPane().add(panel);final JPanel panel_2 = new JPanel();final GridLayout gridLayout = new GridLayout(0, 2);(20);(gridLayout);(panel_2);final JLabel label = new JLabel();;(new Dimension(0, 0));(new Dimension(0, 0));(label);("用户名:");username = new JTextField(20);(new Dimension(0, 0));(username);final JLabel label_1 = new JLabel(); ;(label_1);("密码:");password = new JPasswordField(20); (new MyDocument(6));('*');etSystemLookAndFeelClassName());new LoginIFrame();dd(toolBar, ; final JLabel label = new JLabel(); (0, 0, 0, 0);().getSize());("<html><img width=" + + " height="+ + " src='"+ ().getResource("/")+ "'></html>");}});(label,new Integer);getContentPane().add(DESKTOP_PANE);}/*** 创建工具栏** @return JToolBar*/private JToolBar createToolBar() { etLayout(new GridBagLayout());setBounds(100, 100, 300, 228);final JLabel label_4 = new JLabel();(new Font("", , 14));;("<html>注:每个<b>操作员</b>只能修改自己的密码。