基于java的图书管理系统源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
声明:本系统是基于C/S的图书管理系统,主要使用的是Oracle数据库,下面附所有实现代码package library;
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.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_addres s) 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)
{
}
}
}
}
}
package library;
import javax.swing.*;
import java.awt.*;
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){
}catch(Exception ex){
}
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){
}catch(Exception ex){
}
}
}
}
package library;
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){
}catch(Exception es){
}
}
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){
}
}
}
}
package library;
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);
// 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){
}catch(Exception ex){
}
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){
}catch(Exception ex){
}
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){
}
}
}
}
}
package library;
import javax.swing.*;
import java.awt.*;
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="select student_name,book_name,borrow_date,return_date,is_returned from borrow where book_name='"
+booknamet.getText().trim()+"'";
}
else if(booknamet.getText().trim().equals(""))
{
strSql="select student_name,book_name,borrow_date,return_date,is_returned from borrow where student_name='"
+studentnamet.getText().trim()+"'";
}
else{
strSql="select student_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){
}catch(Exception ex){
}
}
}
}
package library;
import javax.swing.*;
import java.awt.*;
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)
{
}
}
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 java.awt.*;
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-borro wed_count,store_address from book";
String strSql=null;
if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals("")&&presst. getText().trim().equals(""))
{
strSql=strSQL;
}
else
if(booknamet.getText().trim().equals("")&&authornamet.getText().trim().equals(""))
{
strSql="select
book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where press='"
+presst.getText().trim()+"'";
}
else if(authornamet.getText().trim().equals("")&&presst.getText().trim().equals(""))
{
strSql="select
book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where book_name='"
+booknamet.getText().trim()+"'";
}
else if(booknamet.getText().trim().equals("")&&presst.getText().trim().equals(""))
{
strSql="select
book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where author='"
+authornamet.getText().trim()+"'";
}
else{
strSql="select
book_id,book_name,press,author,press_date,price,book_count,borrowed_count,book_count-borro wed_count,store_address from book where book_name='"
+booknamet.getText().trim()
+"'and author='"
+authornamet.getText().trim()
+"'and press='"
+presst.getText().trim()+"'";
}
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));
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(SQLException sqle){
}catch(Exception ex){
}
}
}
}
package library;
import javax.swing.*;
import java.awt.*;
public 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();
c.setLayout(new BorderLayout());
Calendar cal = Calendar.getInstance();
String cdate = sdf.format(cal.getTime());
namelabel=new JLabel("还书者姓名",JLabel.CENTER);
booklabel =new JLabel("书名",JLabel.CENTER);
returndatelabel=new JLabel("日期",JLabel.CENTER);
returnField=new JTextField(15);
returnField.setText(cdate);
try{
String s="";
String strSQL="select student_name from reader where borrow_count!=0";
rs=db.getResult(strSQL);
while(rs.next())
{
readername.addItem(rs.getString(1));
}
}catch(SQLException sqle){
}catch(Exception ex){
}。