图书管理系统-java代码Word版

合集下载

图书管理系统java代码

图书管理系统java代码

组员分工: 刘会敏:图书管理(增,删,查询,修改图书信息)方法 及部分页面, 链接数据库 (DatabaseConn2) 宁俊明:主界面(bookMain),登录注册界面面板(RLogin), 修改个人信息,添加、删除成员 方法 王盛开:登录注册方法(userbean),查看我借的书页面,添加删除成员页面,添加删除图书 页面
} // end main method
@Override public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub //String sex, type;
// 用户点击登录确定按钮 if (e.getSource() == btn_ok1) {
增加图书 (bookAdd, bookbean) 修改图书信息 (bookEdit, bookbean) 删除图书 (bookDel, bookbean) 添加成员 (memberAdd, memberBean) 删除成员 (memberDelete, memberBean )
修改个人信息 (personInfo, personBean) 查看我借的书 (mybook, lookMybook)
登录: 姓名:
注册:
姓名
பைடு நூலகம்密码
学号
密码:
我是:本科生 研 究生
所在院教系师
登录
专业 注册
设置变量: username,sex, password, userID,userType, department, major
向 user 表 插入数据
登录注册页面:
package bookDB;
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

(完整word版)图书管理系统源代码

(完整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_项目开发实例_图书信息管理系统开发文档及源码

图书信息管理系统一、系统功能概述:根据图书信息管理系统的特点,可以将本系统分为2大功能模块,分别为:基础数据维护、系统数据维护。

本系统各个部分及其包括的具体功能模块如下图所示:图书类别表:用户信息表: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写一个图书管理系统的代码

用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图书管理系统-附源码

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的图书管理系统源代码【范本模板】

基于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。

图书管理系统源码(java实现)

图书管理系统源码(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做的一个图书管理系统的源代码.doc

用java做的一个图书管理系统的源代码.doc

用 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 WHEREbookID='"+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 INTOsystemreader(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 INTOmanager(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){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];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) {();}//();();();}}}}。

java编写的图书管理系统源代码

java编写的图书管理系统源代码

/用户登陆数据库代码:importjava.sql.*;classDatabase{Connectioncon;ResultSetrs;Statementstmt;publicDatabase(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载JDBC-ODBC桥驱动程序Stringurl="jdbcdbc:HDB";con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt= //con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,//ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/*根据用户名,获取密码*/publicStringgetPswd(Stringname){try{//rs为执行SQL语句所查询的结果赋给结果集对象rsrs=stmt.executeQuery("SELECTpswdFROMUserWHEREName='"+name+"'");st();//把rs的指针移到最后一行if(rs.getRow()==0){returnnull;}else{StringpswdDB=rs.getString("Pswd");//获取rs结果集中的pswd列的数据returnpswdDB;}}catch(Exceptione){System.out.println(e);returnnull;}}/*增加一行用户名、密码数据*/publicbooleaninsertData(Stringname,Stringpswd){try{Strings=getPswd(name);if(s==null){intrtn=stmt.executeUpdate("INSERTINTOUserVALUES('"+name+"','"+pswd+"')");if(rtn!=0)returntrue;}else{returnfalse;}returnfalse;}catch(Exceptionet){System.out.println(et);returnfalse;}}}//进库数据库代码:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabase{Connectioncon;ResultSetrs;Statementstmt;publicBookDatabase(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载JDBC-ODBC桥驱动程序Stringurl="jdbcdbc:Book";con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/*增加一行用户名、密码数据*/publicbooleaninsertData(Stringid,Stringname,Stringwhere,Stringprice,Stringdate){try{intrtn=stmt.executeUpdate("INSERTINTOBookVALUES('"+id +"','"+name+"','"+where+"','"+price+"','"+date+"')");if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exceptionet){System.out.println(et);returnfalse;}}/**publicbooleandeleteData(Stringid){try{intrtn=*stmt.executeUpdate("DELETEFROMBookWHEREid=001");if(rtn!=0){ *returntrue;}else{returnfalse;}}catch(Exceptione){*System.out.println(e);returnfalse;}}publicbooleanSelect(String*id){try{intrtn=stmt.executeUpdate("SELECT*FROMBookInWHERE *id='"+id+"'");**if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exception*e){System.out.println(e);returnfalse;}}*/}//出库数据库代码:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.Statement;classBookDatabase1{Connectioncon;ResultSetrs;Statementstmt;publicBookDatabase1(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载JDBC-ODBC桥驱动程序Stringurl="jdbcdbc:Book";con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}/**增加一行用户名、密码数据publicbooleaninsertData(Stringid,Stringname,String*where,String**price,Stringdate){try{intrtn=stmt.executeUpdate("INSERTINTO*BookInVALUES('"+id+**"','"+name+"','"+where+"','"+price+"','"+date+"')");**if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exception*et){System.out.println(et);returnfalse;}}*/publicbooleandeleteData(Stringid){try{intrtn=stmt.executeUpdate("DELETEFROMBookWHEREid='"+id+"'");if(rtn!=0){returntrue;}else{returnfalse;}}catch(Exceptione){System.out.println(e);returnfalse;}}/**publicbooleanSelect(Stringid){try{intrtn=*stmt.executeUpdate("SELECT*FROMBookInWHEREid='"+id+"'");if(rtn!=*0){returntrue;}else{returnfalse;}}catch(Exceptione){*System.out.println(e);returnfalse;}}*/}//查询数据库代码;importjava.awt.*;importjava.awt.event.*;importjava.sql.*;importjavax.swing.*;classBookDatabase2extendsJFrame{Stringnumber,name,address,prices,day;Connectioncon;Statementstmt=null;ResultSetresult=null;Stringsql=null;publicBookDatabase2(){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载JDBC-ODBC桥驱动程序Stringurl="jdbc:odbc:Book";con=DriverManager.getConnection(url);//连接数据库HDB//stmt提供一个创建SQL查询、执行查询、得到返回结果的空间stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);}catch(Exceptionex){System.out.println(ex);}}publicvoidselect(Stringid){try{sql="SELECT*FROMBookwhereid='"+id+"'";result=stmt.executeQuery(sql);while(result.next()){number=result.getString(1);name=result.getString(2);address=result.getString(3);prices=result.getString(4);day=result.getString(4);}JOptionPane.showMessageDialog(BookDatabase2.this,"成功查询图书!\n"+"图书ID:"+number+"\n"+"图书名称:"+name+"\n"+"出版社"+address+"\n"+"价格:"+prices+"\n"+"出版日期:"+day+"\n","提示",JOptionPane.ERROR_MESSAGE);}catch(Exceptione){System.out.println(e);}}。

图书借阅管理系统java代码

图书借阅管理系统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书店管理系统源代码

java书店管理系统源代码

Java 源代码publicclass loaduser {public String user;public String password;boolean b1;loaduser(String s1,String s2){user=s1;password=s2;}void load(){System.out。

println(" 书店管理销售系统");System.out.println(”**************************************");System。

out。

println(” 1、登录系统”);System.out.println(” 2、退出系统”);System。

out.println("**************************************”);System。

out.println("请选择:”);int m;Scanner s=new Scanner(System。

in);m=s。

nextInt();if(m==1){for(int i=0;i〈3;i++){System.out。

println("请输入账户名和密码”);String s3,s4;Scanner ss=new Scanner(System。

in);s3=s。

next();s4=s。

next();if(user。

equals(s3)&&password.equals(s4)) b1=true;else b1=false;if(i==0&&b1==false)System。

out.println("用户名或密码输入错误一次,还有两次机会!”);if(i==1&&b1==false)System。

out。

println(”用户名或密码输入错误两次,还有一次机会!");if(i==2&&b1==false){System.out.println(”三次输入错误,退出系统!”);System。

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图书馆管理系统附全代码课程设计报告精编WORD版

Java图书馆管理系统附全代码课程设计报告精编WORD版

J a v a图书馆管理系统附全代码课程设计报告精编W O R D版IBM system office room 【A0816H-A0912AAAHH-GX8Q8-《数据库系统概论》课程报告课题名称:小型图书管理系统课题负责人名(学号):best同组成员名单(角色):指导教师:评阅成绩:评阅意见:提交报告时间:2015年12月15日小型图书管理系统计算机科学与技术专业学生指导老师[摘要]随着计算机技术的飞速发展,利用计算机来获得和处理信息是当今信息管理的一大特点。

伴随计算机硬件的快速发展,有关信息管理的软件——数据库系统软件也在迅猛发展着。

图书馆是高等院校的重要组成部门,是教师和学生获取知识的重要场所。

由于图书馆主要从事大量的图书资料的储存和流通。

所以一直以来,计算机在图书馆的图书管理中得到了广泛的应用。

本系统实现图书信息管理的系统化,规范化和自动化,以最大程度提高操作人员的办公效率。

关键词:JAVA、JDBC、SQL Server、数据库、图书馆管理一、实验题目:小型图书管理系统二、实验的目的和要求:完成一个小型图书管理系统,功能要求如下:1)能够通过书籍基本信息(包括:书号、书名、出版社、出版日期、作者、内容摘要)单个或以AND方式组合多个条件查询书籍信息;2)对于每一种书籍,除可查看其基本信息之外还可查看其总数以及目前在馆数量3)可增添新的书籍4)可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)5)可修改书籍的基本信息6)能够通过读者基本信息(包括:证号、姓名、性别、系名、年级)单个或以AND方式组合多个条件查询读者信息7)对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期8)可增添新的读者9)可删除已有读者(如该读者有尚未归还的借书,则不允许删除)10)可修改读者的基本信息11)可完成借还书籍的手续12)还书时如超期,应该显示超期天数13)借书时如果有超期的书没有还,则不允许借书14)可查询有哪些读者有超期的书没有还,列出这些读者的基本信息三、实验的环境:1、硬件环境:CPU: Intel(R) Core i5-3230 2.60GHzRAM: 8GB2、软件环境:操作系统:Windows 7 Ultimate SP1编译软件:Eclipse LunaMicrosoft SQL Server 2014四、系统ER图五、表结构定义(使用表格说明)六、系统功能模块1)能够通过书籍基本信息单个或组合多个条件查询书籍信息;2)对于每一种书籍,除可查看其基本信息之外还可查看其总数以及目前在馆数量3)可增添新的书籍4)可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)5)可修改书籍的基本信息6)能够通过读者基本信息单个或组合多个条件查询读者信息7)对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期8)可增添新的读者9)可删除已有读者(如该读者有尚未归还的借书,则不允许删除)10)可修改读者的基本信息11)可完成借还书籍的手续12)还书时如超期,应该显示超期天数13)借书时如果有超期的书没有还,则不允许借书14)可查询有哪些读者有超期的书没有还,列出这些读者的基本信息七、程序框架流程图九、程序运行结果八、核心代码AddBook.javaimport java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;public class AddBook extends JFrame implements ActionListener { SQLOperation op = new SQLOperation();Container c = getContentPane();JPanel p1 = new JPanel();JLabel bookNumber = new JLabel("Book Number:"); JLabel bookName = new JLabel("Book Name:"); JLabel bookAuthor = new JLabel("Book Author:"); JLabel press = new JLabel("Press:");JLabel pressTime = new JLabel("Press time:"); JLabel bookAbstract = new JLabel("Abstract:"); JLabel storage = new JLabel("Storage:");JLabel remain = new JLabel("Remain");JLabel remain1 = new JLabel("Update with Storage"); JTextField numberField = new JTextField(); JTextField nameField = new JTextField(); JTextField authorField = new JTextField();JTextField pressField = new JTextField(); JTextField pressTimeField = new JTextField(); JTextField abstractField = new JTextField(); JTextField storageField = new JTextField(); JButton cancel = new JButton("Cancel"); JButton confirm = new JButton("Confirm!!"); public AddBook() {c.add(p1, BorderLayout.NORTH);p1.setLayout(new GridLayout(9, 2, 20, 10));p1.add(bookNumber);p1.add(numberField);p1.add(bookName);p1.add(nameField);p1.add(bookAuthor);p1.add(authorField);p1.add(press);p1.add(pressField);p1.add(pressTime);p1.add(pressTimeField);p1.add(bookAbstract);p1.add(abstractField);p1.add(storage);p1.add(storageField);p1.add(remain);p1.add(remain1);p1.add(cancel);p1.add(confirm);cancel.addActionListener(this);confirm.addActionListener(this);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == cancel) {this.dispose();}if (e.getSource() == confirm) {this.dispose();BookInfo book = newBookInfo(numberField.getText(),nameField.getText(), authorField.getText(),pressField.getText(), pressTimeField.getText(),abstractField.getText(),Integer.parseInt(storageField.getText()),Integer.parseInt(storageField.getText()));ArrayList<String> strArray = newArrayList<String>();strArray = op.addBookJudgement();int n = 0;int replicate = 0;while (n < Integer.parseInt(strArray.get(0))) {n++;if(numberField.getText().equals(strArray.get(n))) {replicate++;}}if (replicate == 0) {op.saveBook(book);JOptionPane.showMessageDialog(null, "Add a book successfully!","Information", RMATION_MESSAGE);} else {JOptionPane.showMessageDialog(null,"This book(number) has already existed!", "Warning",RMATION_MESSAGE);}}}}AddReader.javaimport java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;public class AddReader extends JFrame implements ActionListener { SQLOperation op = new SQLOperation();Container c = getContentPane();JPanel p1 = new JPanel();JLabel readerNumber = new JLabel("Reader Number:");JLabel readerName = new JLabel("Reader Name:"); JLabel sex = new JLabel("Sex:");JLabel dpt = new JLabel("Department:");JLabel grade = new JLabel("Grade:"); JTextField numberField = new JTextField(); JTextField nameField = new JTextField(); JTextField sexField = new JTextField(); JTextField dptField = new JTextField(); JTextField gradeField = new JTextField(); JButton cancel = new JButton("Cancel"); JButton confirm = new JButton("Confirm!!"); public AddReader() {c.add(p1, BorderLayout.NORTH);p1.setLayout(new GridLayout(6, 2, 20, 10));p1.add(readerNumber);p1.add(numberField);p1.add(readerName);p1.add(nameField);p1.add(sex);p1.add(sexField);p1.add(dpt);p1.add(dptField);p1.add(grade);p1.add(gradeField);p1.add(cancel);p1.add(confirm);cancel.addActionListener(this); confirm.addActionListener(this);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == cancel) {this.dispose();}if (e.getSource() == confirm) {this.dispose();ReaderInfo reader = newReaderInfo(numberField.getText(),nameField.getText(), sexField.getText(),dptField.getText(),Integer.parseInt(gradeField.getText()));ArrayList<String> strArray = newArrayList<String>();strArray = op.addReaderJudgement();int n = 0;int replicate = 0;while (n < Integer.parseInt(strArray.get(0))) {n++;if(numberField.getText().equals(strArray.get(n))) {replicate++;}}if (replicate == 0) {if (!sexField.getText().equals("boy") && !sexField.getText().equals("girl")) {JOptionPane.showMessageDialog(null,"In the Sex field, you can only input 'boy' or 'girl'!","Warning", RMATION_MESSAGE);} else {op.saveReader(reader);JOptionPane.showMessageDialog(null,"Add a reader successfully!", "Information",RMATION_MESSAGE);}} else {JOptionPane.showMessageDialog(null,"This reader(number) has already existed!", "Warning",RMATION_MESSAGE);}}}}BookDetails.javaimport java.awt.BorderLayout;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;import javax.swing.table.DefaultTableModel;public class BookDetails extends JFrame implements ActionListener { SQLOperation op = new SQLOperation();Container c = getContentPane();JPanel p1 = new JPanel();JPanel p2 = new JPanel();JPanel p3 = new JPanel();JLabel bookNumber = new JLabel("Book Number:");JLabel bookName = new JLabel("Book Name:");JLabel author = new JLabel("Author:");JLabel press = new JLabel("Press:");JLabel pressTime = new JLabel("Press time:"); JLabel bookAbstract = new JLabel("Abstract:"); JLabel storage = new JLabel("Storage:"); JLabel remain = new JLabel("Remain:"); JLabel numberField = new JLabel();JLabel nameField = new JLabel();JLabel authorField = new JLabel();JLabel pressField = new JLabel();JLabel pressTimeField = new JLabel();JLabel abstractField = new JLabel();JLabel storageField = new JLabel();JLabel remainField = new JLabel();JButton cancel = new JButton("Cancel");JLabel details = new JLabel("Borrow and reaturn details");Object[] s = { "Reader number", "Borrow time", "Deadline", "Over time" };Object[][] ob1 = new Object[7][4];JTable table = new JTable(ob1, s);JScrollPane scrollPane = new JScrollPane(table);public BookDetails(String number) {BookInfo book = new BookInfo(number);ob1 = op.borrowListForBook(number);for (int i = 0; i < 5; i++) {DefaultTableModel books = new DefaultTableModel(ob1, s);for (int n = 0; n < 7; n++) {for (int m = 0; m < 4; m++) {ob1[n][m] = this.ob1[n][m];}table.setModel(books);table.invalidate();}}ArrayList<String> strArray = new ArrayList<String>(); strArray = op.outputBook(book);numberField.setText(number);nameField.setText(strArray.get(1));authorField.setText(strArray.get(2));pressField.setText(strArray.get(3)); pressTimeField.setText(strArray.get(4)); abstractField.setText(strArray.get(5));storageField.setText(strArray.get(6)); remainField.setText(strArray.get(7));c.add(p1, BorderLayout.NORTH);c.add(p2, BorderLayout.CENTER);c.add(p3, BorderLayout.SOUTH);p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber);p1.add(numberField);p1.add(bookName);p1.add(nameField);p1.add(author);p1.add(authorField);p1.add(press);p1.add(pressField);p1.add(pressTime);p1.add(pressTimeField);p1.add(bookAbstract);p1.add(abstractField);p1.add(storage);p1.add(storageField);p1.add(remain);p1.add(remainField);p1.add(details);scrollPane.setBounds(0, 0, 800, 300);p2.add(scrollPane);p3.add(cancel);table.setPreferredScrollableViewportSize(new Dimension(400, 100));cancel.addActionListener(this);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == cancel) {this.dispose();}}}BookInfo.javapublic class BookInfo {private String number, name, author, press, pressTime, bookAbstract;private int total, remain;// default constructorpublic BookInfo() {}public BookInfo(String number) {this.number = number;}public BookInfo(String number, String name) {this.number = number; = name;}public BookInfo(String number, String name, String author, String press,String pressTime, String bookAbstract, int total, int remain) {this.number = number; = name;this.author = author;this.press = press;this.pressTime = pressTime;this.bookAbstract = bookAbstract;this.total = total;this.remain = remain;}public void setRemain(int i) {this.remain=i;}public String getNumber() {return number;}public String getName() {return name;}public String getAuthor() {return author;}public String getPress() {return press;}public String getPressTime() {return pressTime;}public String getBookAbstract() {return bookAbstract;}public int getTotal() {return total;}public int getRemain() {return remain;}}BookRetrieval.javaimport java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Font;import java.awt.GridLayout;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;import javax.swing.table.DefaultTableModel;class BookRetrieval extends JFrame implements ActionListener { SQLOperation op = new SQLOperation();Container c = getContentPane();JPanel p1 = new JPanel();JPanel p4 = new JPanel();JPanel p5 = new JPanel();JLabel bookNumber = new JLabel("Book Number:");JLabel bookName = new JLabel("Book Name:");JTextField number = new JTextField();JTextField name = new JTextField();JButton back = new JButton("Back (Fresh)");JButton addBook = new JButton("Add a book");JButton deleteBook = new JButton("Delete a book");JButton editBook = new JButton("Edit a book");JButton search = new JButton("Search for details!");JButton borrowBook = new JButton("Borrow a book");JButton returnBook = new JButton("Return a book");Font font1 = new Font("00", Font.BOLD, 20);Object[] s = { "Number", "Name", "Author", "Press", "Press Time", "Abstract", "Storage", "Remain" };Object[][] ob = new Object[40][8];JTable table = new JTable(ob, s);JScrollPane scrollPane = new JScrollPane(table);public BookRetrieval() {BookInfo book = new BookInfo();ob = op.allBook(book);for (int i = 0; i < 5; i++) {DefaultTableModel books = new DefaultTableModel(ob, s);for (int n = 0; n < 20; n++) {for (int m = 0; m < 8; m++) {ob[n][m] = this.ob[n][m];}table.setModel(books);table.invalidate();}}c.add(p4, BorderLayout.NORTH);c.add(p1, BorderLayout.CENTER);c.add(p5, BorderLayout.SOUTH); search.setFont(font1);p4.setLayout(new GridLayout(2, 4, 20, 10)); p4.add(back);p4.add(addBook);p4.add(editBook);p4.add(deleteBook);p4.add(borrowBook);p4.add(returnBook);p1.setLayout(null);scrollPane.setBounds(0, 0, 800, 300);p1.add(scrollPane);p5.setLayout(new GridLayout(5, 1, 0, 0));p5.add(bookNumber);p5.add(number);p5.add(bookName);p5.add(name);p5.add(search);table.setPreferredScrollableViewportSize(new Dimension(400, 300));addBook.addActionListener(this);search.addActionListener(this);back.addActionListener(this);deleteBook.addActionListener(this);editBook.addActionListener(this);borrowBook.addActionListener(this);returnBook.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource() == search) {ArrayList<String> strArray = new ArrayList<String>();strArray = op.addBookJudgement();String s1 = number.getText();String s2 = name.getText();int n = 0;int replicate = 0;while (n < Integer.parseInt(strArray.get(0))) {n++;if (s1.equals(strArray.get(n))) {replicate++;}}ArrayList<String> strArray1 = newArrayList<String>();strArray1 = op.addBookJudgement1();int n1 = 0;int replicate1 = 0;while (n1 < Integer.parseInt(strArray1.get(0))) {n1++;if (s2.equals(strArray1.get(n1))) {replicate1++;}}if (replicate == 0 && replicate1 == 0) {JOptionPane.showMessageDialog(null,"Please input a correct book number or name!","Warning",RMATION_MESSAGE);} else if (replicate != 0 || replicate1 != 0) {if (replicate == 0 && replicate1 != 0) {BookInfo book = new BookInfo(s1, s2);String s = op.searchBookByName(book);BookDetails f = new BookDetails(s);//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Book Details");f.setLocation(300, 200);f.setSize(480, 470);f.setVisible(true);} else if (replicate != 0) {BookDetails f = new BookDetails(s1);//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Book Details");f.setLocation(300, 200);f.setSize(480, 470);f.setVisible(true);}}}if (e.getSource() == back) {this.dispose();MyFrame f = new MyFrame();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Library Management System");f.setLocation(300, 200);f.setSize(580, 300);f.setVisible(true);}if (e.getSource() == addBook) {AddBook f = new AddBook();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Add a book");f.setLocation(300, 200);f.setSize(300, 400);f.setVisible(true);}if (e.getSource() == deleteBook) {DeleteBook f = new DeleteBook();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Delete a book");f.setLocation(300, 200);f.setSize(300, 200);f.setVisible(true);}if (e.getSource() == borrowBook) {BorrowBook f = new BorrowBook();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Borrow a book");f.setLocation(300, 200);f.setSize(300, 200);f.setVisible(true);}if (e.getSource() == returnBook) {ReturnBook f = new ReturnBook();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Return a book");f.setLocation(300, 200);f.setSize(300, 200);f.setVisible(true);}if (e.getSource() == editBook) {SelectEdit f = new SelectEdit();//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);f.setTitle("Edit a book");f.setLocation(300, 200);f.setSize(300, 200);f.setVisible(true);}}}BorrowBook.javaimport java.awt.BorderLayout;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;public class BorrowBook extends JFrame implements ActionListener { SQLOperation op = new SQLOperation();Container c = getContentPane();JPanel p1 = new JPanel();JLabel bookNumber = new JLabel("Book Number:");JTextField numberField = new JTextField();JLabel readerNumber = new JLabel("Reader Number:");JTextField readerNumberField = new JTextField(); JButton cancel = new JButton("Cancel"); JButton borrow = new JButton("Borrow!!"); public BorrowBook() {c.add(p1, BorderLayout.NORTH);p1.setLayout(new GridLayout(3, 2, 20, 10));p1.add(bookNumber);p1.add(numberField);p1.add(readerNumber);p1.add(readerNumberField);p1.add(cancel);p1.add(borrow);cancel.addActionListener(this);borrow.addActionListener(this);}public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == cancel) {this.dispose();}if (e.getSource() == borrow) {String bookNumber = numberField.getText();ArrayList<String> strArray = new ArrayList<String>();strArray = op.addBookJudgement();int n = 0;int replicate = 0;while (n < Integer.parseInt(strArray.get(0))) {n++;if (bookNumber.equals(strArray.get(n))) {replicate++;}}String readerNumber = readerNumberField.getText();ArrayList<String> strArray1 = newArrayList<String>();strArray1 = op.addReaderJudgement();int n1 = 0;int replicate1 = 0;while (n1 < Integer.parseInt(strArray1.get(0))) {n1++;if (readerNumber.equals(strArray1.get(n1))) {replicate1++;}}if (replicate == 0 || replicate1 == 0) {JOptionPane.showMessageDialog(null,"Please input a correct book number and a reader number!","Warning", RMATION_MESSAGE);} else {BookInfo book = new BookInfo(bookNumber);ArrayList<String> s = new ArrayList<String>();s = op.outputBook(book);if (Integer.parseInt(s.get(7)) > 0) {int s1 =op.reBorrowCheck(numberField.getText(),readerNumberField.getText());if (s1 == 1) {JOptionPane.showMessageDialog(null,"You have borrowed this book, can not reborrow it!","Unsuccessful",。

用java做的一个图书管理系统的源代码

用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_项目开发实例_图书信息管理系统开发文档及源码

java_项目开发实例_图书信息管理系统开发文档及源码

java_项目开发实例_图书信息管理系统开发文档及源码一、系统功能概述:根据图书信息管理系统的特点,可以将本系统分为2大功能模块,分别为:基础数据维护、系统数据维护。

本系统各个部分及其包括的具体功能模块如下图所示:二、数据库设计:字段名说明类型长度及备注ISBN 国际标准书号Varchar(13) 主键typeId 图书类型id IntBookname 书名Varchar(40)Writer 作者Varchar(21)Translater 译者Varchar(30) 可以为空Publisher 出版社Varchar(50)Date 出版日期SmalldatetimePrice 价格money三、系统源代码: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' 冲突。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.*;import javax.swing.*;//---------------------------------------------------------------------------------------------------------class Tsgl {public static void main(String args[]) {dbframe db = new dbframe("图书管理程序");}}// 图书管理系统主界面class dbframe extends Frame implements ActionListener {MenuBar daohang = new MenuBar(); // 建立菜单栏Menu mfile = new Menu("功能"); // 建立“功能”菜单组Menu mhelp = new Menu("帮助"); // 建立“帮助”菜单组MenuItem mdenglu = new MenuItem("登陆");MenuItem mchaxun = new MenuItem("查询");MenuItem mtianjia = new MenuItem("添加");MenuItem mshanchu = new MenuItem("删除");MenuItem mexit = new MenuItem("退出");MenuItem mhelpp = new MenuItem("关于");Denglu pdenglu=new Denglu();Ptianjia ptianjia = new Ptianjia();Pmain pmain = new Pmain();Pchaxun pchaxun = new Pchaxun();Pshanchu pshanchu = new Pshanchu();dbframe(String s) { // 在窗口上添加菜单选项setTitle(s);mfile.add(mdenglu);mfile.add(mtianjia);mfile.add(mchaxun);mfile.add(mshanchu);mfile.add(mexit);mhelp.add(mhelpp);daohang.add(mfile);daohang.add(mhelp);setMenuBar(daohang);add(pmain);addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { System.exit(0);}});setBounds(200, 200, 340, 250);setResizable(false);setVisible(true);mexit.addActionListener(this);mdenglu.addActionListener(this);mtianjia.addActionListener(this);mchaxun.addActionListener(this);mshanchu.addActionListener(this);mhelpp.addActionListener(this);validate();} // 窗口事件监听public void actionPerformed(ActionEvent e) { if (e.getSource() == mexit)System.exit(0);if(e.getSource()==mdenglu){removeAll();add(pdenglu);validate();}if (e.getSource() == mtianjia) {removeAll();add(ptianjia);validate();} // 图书添加功能if (e.getSource() == mchaxun) {removeAll();add(pchaxun);validate();} // 图书查询功能if (e.getSource() == mshanchu) {removeAll();add(pshanchu);validate();} // 图书删除功能if (e.getSource() == mhelpp) {JOptionPane.showMessageDialog(this, "欢迎使用图书管理系统", "关于本系统",RMATION_MESSAGE);}} // 各功能菜单事件监听}//class Ptianjia extends Panel implements ActionListener {TextField tname, tauthor, tpublish, tdate, tcomment;Label lname, lauthor, lpublish, ldate, lcomment;Button btn;Ptianjia() {setLayout(null);btn = new Button("添加"); // 创建“添加”按钮tname = new TextField();tauthor = new TextField();tpublish = new TextField();tdate = new TextField();tcomment = new TextField(); // 创建5个文本框lname = new Label("书名");lauthor = new Label("作者");lpublish = new Label("出版社");ldate = new Label("出版日期");lcomment = new Label("评论");add(lname);add(tname);add(lauthor);add(tauthor);add(lpublish);add(tpublish);add(ldate);add(tdate);add(lcomment);add(tcomment);add(btn); // 添加“按钮”到窗口面板上lname.setBounds(10, 10, 70, 25);tname.setBounds(90, 10, 220, 25);lauthor.setBounds(10, 40, 70, 25);tauthor.setBounds(90, 40, 220, 25);lpublish.setBounds(10, 70, 70, 25);tpublish.setBounds(90, 70, 220, 25);ldate.setBounds(10, 100, 70, 25);tdate.setBounds(90, 100, 220, 25);lcomment.setBounds(10, 130, 70, 25);tcomment.setBounds(90, 130, 220, 25);btn.setBounds(130, 160, 70, 25); // 设置按钮位置btn.addActionListener(this); // 设置按钮监听setSize(340, 250); // 设置窗口大小setBackground(Color.white); // 设置窗口背景颜色setVisible(true);validate();}public void actionPerformed(ActionEvent e) {String sname = tname.getText();String sauthor = tauthor.getText();String spublish = tpublish.getText();String sdate = tdate.getText();String scomment = tcomment.getText();String insertstr = "insert into book values" + "(" + "'" + sname + "'"+ "," + "'" + sauthor + "'" + "," + "'" + spublish + "'" + ","+ "'" + sdate + "'" + "," + "'" + scomment + "'" + ")"; // SQL 语句Connection con;Statement sta;ResultSet rs;try {Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载JDBC驱动} catch (ClassNotFoundException ee) {System.out.println("" + ee);}try {con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl"); // 连接数据库sta = con.createStatement();sta.executeUpdate(insertstr); // 执行SQL语句con.close(); // 关闭数据库tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText(""); // 重新初始化文本框内容JOptionPane.showMessageDialog(this, "添加成功", "图书管理系统",RMATION_MESSAGE);} catch (SQLException eee) {System.out.println("" + eee);tname.setText("");tauthor.setText("");tpublish.setText("");tdate.setText("");tcomment.setText("");JOptionPane.showMessageDialog(this, "添加失败", "图书管理系统",JOptionPane.WARNING_MESSAGE);}}}class Pmain extends Panel { // 窗口面板布局Label l1 = new Label("图书管理系统", Label.CENTER);Label l2 = new Label("计算机学院", Label.RIGHT);Label l3 = new Label("", Label.RIGHT);Label l4 = new Label("作者:JHL", Label.RIGHT);Pmain() {setLayout(null);setBackground(Color.white);add(l1);add(l2);add(l3);add(l4);l1.setBounds(10, 60, 320, 40);l2.setBounds(240, 120, 80, 22);l3.setBounds(240, 142, 80, 22);l4.setBounds(240, 164, 80, 22);setSize(340, 250);setVisible(true);validate();}}class Pchaxun extends Panel implements ActionListener {// 图书查询Choice cchaxun;TextField tchaxun;Button btnchaxun;TextArea tachaxun;Pchaxun() {setLayout(null);cchaxun = new Choice(); // 创建下拉菜单cchaxun.add("书名");cchaxun.add("作者");cchaxun.add("出版社");tchaxun = new TextField();btnchaxun = new Button("查询"); // 创建按钮tachaxun = new TextArea(); // 创建多行文本框add(cchaxun);add(tchaxun);add(btnchaxun);add(tachaxun);tchaxun.setText("");cchaxun.setBounds(10, 10, 65, 20);tchaxun.setBounds(85, 10, 180, 20);btnchaxun.setBounds(275, 10, 40, 20);tachaxun.setBounds(10, 40, 305, 145);cchaxun.select(0); // 下拉菜单的初始选项setSize(340, 250); // 设置窗口大小setBackground(Color.white);setVisible(true);btnchaxun.addActionListener(this);validate();}public void actionPerformed(ActionEvent e) {int i = cchaxun.getSelectedIndex();String s = tchaxun.getText();if (s.equals(""))JOptionPane.showMessageDialog(this, "查询内容不能为空", "查询系统",JOptionPane.WARNING_MESSAGE);else {Connection con;Statement sql;ResultSet rs;try {Class.forName("oracle.jdbc.driver.OracleDriver"); // 加载JDBC 驱动} catch (ClassNotFoundException ee) {System.out.println("" + ee);}try {con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl");// 连接数据库sql = con.createStatement();if (i == 0) // 根据下拉菜单的选项执行不同的SQL语句rs = sql.executeQuery("select * from book where bookName ="+ "'" + s + "'");else if (i == 1)rs = sql.executeQuery("select * from book where author ="+ "'" + s + "'");elsers = sql.executeQuery("select * from book where publisher ="+ "'" + s + "'");tachaxun.setText("");String panduan = "false";while (rs.next()) {panduan = "true";tachaxun.append("书名:" + rs.getString(1) + "\n");tachaxun.append("作者:" + rs.getString(2) + "\n");tachaxun.append("出版社:" + rs.getString(3) + "\n");tachaxun.append("出版日期:" + rs.getString(4) + "\n");tachaxun.append("评论:" + rs.getString(5) + "\n");} // 显示查询到的图书信息rs = sql.executeQuery("select count(*) from book"); // 统计所有图书数while (rs.next()) {tachaxun.append("图书馆暂有" + rs.getString(1) + "本图书");} // 显示所有图书数量信息con.close(); // 关闭数据库if (panduan.equals("false"))JOptionPane.showMessageDialog(this, "没有该记录", "查询系统",JOptionPane.WARNING_MESSAGE);} catch (SQLException eee) {System.out.println(eee);}}}}class Pshanchu extends Panel implements ActionListener { // 删除功能模块Choice cshanchu;TextField tshanchu;Button btnshanchu;Label l1 = new Label("", Label.CENTER);Label l2 = new Label("计算机学院", Label.RIGHT);Label l3 = new Label("", Label.RIGHT);Label l4 = new Label("作者:ZCS", Label.RIGHT);Pshanchu() {setLayout(null);cshanchu = new Choice(); // 创建下拉菜单cshanchu.add("书名");tshanchu = new TextField();btnshanchu = new Button("删除"); // 创建按钮add(cshanchu);add(tshanchu);add(btnshanchu);add(l1);add(l2);add(l3);add(l4); // 添加标签、按钮等到窗口面板tshanchu.setText("");cshanchu.setBounds(10, 10, 65, 20);tshanchu.setBounds(85, 10, 180, 20);btnshanchu.setBounds(275, 10, 40, 20);l1.setBounds(10, 40, 300, 40);l2.setBounds(240, 130, 80, 22);l3.setBounds(240, 152, 80, 22);l4.setBounds(240, 174, 80, 22);cshanchu.select(0);setSize(340, 250); // 设置窗口大小setBackground(Color.white);setVisible(true);btnshanchu.addActionListener(this);validate();}public void actionPerformed(ActionEvent e) {String s = tshanchu.getText();if (s.equals(""))JOptionPane.showMessageDialog(this, "请输入要删除的图书", "删除功能",JOptionPane.WARNING_MESSAGE);else {Connection con;Statement sql;ResultSet rs;try {Class.forName("oracle.jdbc.driver.OracleDriver");} catch (ClassNotFoundException ee) {System.out.println("" + ee);}try {con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl");sql = con.createStatement();rs = sql.executeQuery("select * from book where bookName ="+ "'" + s + "'");if (!rs.next())JOptionPane.showMessageDialog(this, "没有该图书", "删除功能",JOptionPane.WARNING_MESSAGE);else {int n = JOptionPane.showConfirmDialog(this, "确认删除吗?","删除功能", JOptionPane.YES_NO_OPTION);if (n == JOptionPane.YES_OPTION) {sql.executeUpdate("delete from book where bookName ="+ "'" + s + "'");JOptionPane.showMessageDialog(this, "删除成功", "删除功能",RMATION_MESSAGE);tshanchu.setText("");} elsetshanchu.setText("");con.close();}} catch (SQLException eee) {System.out.println(eee);}}}}class Denglu extends Panel implements ActionListener { Label lzhanghao;TextField tzhanghao;Label lmima;TextField tmima;Button bdenglu;Denglu(){setLayout(null);lzhanghao=new Label("账号");tzhanghao=new TextField();lmima=new Label("密码");tmima=new TextField();bdenglu=new Button("登陆");add(lzhanghao);add(tzhanghao);add(lmima);add(tmima);add(bdenglu);tzhanghao.setText("");tmima.setText("");lzhanghao.setBounds(50, 25, 50, 30);tzhanghao.setBounds(100, 30, 200, 20);lmima.setBounds(50, 80, 50, 30);tmima.setBounds(100, 80, 200, 20);bdenglu.setBounds(140, 130, 50, 30);setBackground(Color.white);setVisible(true);bdenglu.addActionListener(this);validate();}public void actionPerformed(ActionEvent e) {String x=tzhanghao.getText();String y=tmima.getText();if(x.equals("weifang")&&y.equals("123") ){JOptionPane.showMessageDialog(this, "登陆成功", "提示",RMATION_MESSAGE);}else{JOptionPane.showMessageDialog(this, "账号或者密码错误","提示",JOptionPane.WARNING_MESSAGE);}}}。

相关文档
最新文档