1、声明:本系统是基于 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;
2、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 ActionListenerDataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2;JLabel book_id_label,boo
3、k_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
4、 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
5、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_TextF
6、ield=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.addIt
7、em(“荷花池图书馆“);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.a
8、dd(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);pan
9、el1.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,Borde
10、rLayout.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_T
11、extField.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
12、 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
13、(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 tryString s
14、trSQL=“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.ge
15、tText().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,“添加图书成功“);elseJOptionPane.showMessageDialog(null,“添加图书失败“);this.
16、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 ActionListenerDataBaseManager db
17、=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();tryString strSQL=“select book_name from
18、 book where book_countborrowed_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(“确定“
19、);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)tryString strSQL=“select borro
20、wed_count from book where book_name=“+bb.getSelectedItem()+“;rs=db.getResult(strSQL);if(!rs.first()JOptionPane.showMessageDialog(null,“书库里没有你要删除的书“);elseString strSql=“delete from book where book_name=“+bb.getSelectedItem()+“and borrowed_count=0“;rs.first();int count=rs.getInt(1);if(!(count=0)JOptio
21、nPane.showMessageDialog(null,“此书还有学生没有还,不可删除“);else if(db.updateSql(strSql)JOptionPane.showMessageDialog(null,“删除成功“);db.closeConnection();this.dispose();elseJOptionPane.showMessageDialog(null,“删除失败“);db.closeConnection();this.dispose();catch(SQLException sqle)System.out.println(sqle.toString();catc
22、h(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;impo
23、rt javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;public class book_modify extends JFrame implements ActionListenerDataBaseManager db=new DataBaseManager();ResultSet rs;JPanel panel1,panel2,panel3;JLabel TipLabel=new JLabel(“输入书名点确定 ,将调出此书的相
24、关信息“);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 Bor
25、derLayout();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(“价格“,J
26、Label.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_
27、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=
28、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)
29、;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.
30、setText(“);price_TextField.setText(“);else if(e.getSource()=yes)tryString 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“);p
31、ress_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.ge
32、tSource()=update)tryString 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_nam
33、e=“+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;im
34、port 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.
35、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 ActionListenerDataBaseManager db=new DataBaseManager();ResultSet rs;
36、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=getContentP
37、ane();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.form
38、at(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=n
39、ew 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(“否“);tryString strSql=“select student_name from reader “;rs=db.getResult(strSql);whil
40、e(rs.next()borrownameBox.addItem(rs.getString(1);catch(SQLException sqle)System.out.println(sqle.toString();catch(Exception ex)System.out.println(ex.toString();tryString strSQL=“select book_name from book where book_countborrowed_count“;rs=db.getResult(strSQL);while(rs.next()booknameBox.addItem(rs.g
41、etString(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);pan
42、el1.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.ad
43、dActionListener(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.getSourc
44、e()=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, “对不起,现在书库没
45、有书“);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.forma
46、t(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)JOptio
47、nPane.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.
48、closeConnection();this.dispose();elseJOptionPane.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 ActionListenerDataBaseManager db=new DataBaseManager();ResultSet rs;Container c;JPanel panel1,panel2;JLabel bookname,studentname;JTextField bookname