![做的簡單圖書管理系統(tǒng)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/9/2edfb592-6bee-48e0-a548-423b612a1efc/2edfb592-6bee-48e0-a548-423b612a1efc1.gif)
![做的簡單圖書管理系統(tǒng)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/9/2edfb592-6bee-48e0-a548-423b612a1efc/2edfb592-6bee-48e0-a548-423b612a1efc2.gif)
![做的簡單圖書管理系統(tǒng)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/9/2edfb592-6bee-48e0-a548-423b612a1efc/2edfb592-6bee-48e0-a548-423b612a1efc3.gif)
![做的簡單圖書管理系統(tǒng)_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/9/2edfb592-6bee-48e0-a548-423b612a1efc/2edfb592-6bee-48e0-a548-423b612a1efc4.gif)
![做的簡單圖書管理系統(tǒng)_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-3/9/2edfb592-6bee-48e0-a548-423b612a1efc/2edfb592-6bee-48e0-a548-423b612a1efc5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、package Tools;import java.sql.*;import org.junit.Test;public class ConnDBConnection con;Statement stmt = null;ResultSet rs = null;String driverName="com.mysql.jdbc.Driver" /驅(qū)動程序名String user="root" /MySQL配置時的用戶名String password="root" /MySQL配置時的密碼String url="jdbc:mys
2、ql:/localhost:3306/library" /URL指向要訪問的數(shù)據(jù)庫地址/連接數(shù)據(jù)庫public ConnDB()tryClass.forName(driverName); /加載數(shù)據(jù)庫程序 con = DriverManager.getConnection(url, user, password); /使用getConnection()方法,連接MySQL數(shù)據(jù)庫!if (!con.isClosed()System.out.println("連接成功!");elseSystem.out.println("連接失敗!");catch
3、(Exception e)System.err.println(e.getMessage();/執(zhí)行SQL查詢,并返回查詢結(jié)果集public ResultSet select(String sql)tryClass.forName(driverName);con = DriverManager.getConnection(url,user,password);stmt=con.createStatement();rs=stmt.executeQuery(sql);catch(Exception e)System.err.println(e.getMessage();return rs;Test
4、public void testSelect()/*執(zhí)行SQL更新,并返回影響到的記錄條數(shù)*/public int update(String sql)int rs=0;tryClass.forName(driverName);con=DriverManager.getConnection(url,user,password);stmt=con.createStatement();rs=stmt.executeUpdate(sql);catch(Exception e)System.err.println(e.getMessage();return rs;public void testupd
5、ate()public static void main(String args)new ConnDB();package Library.Management.System;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import javax.swing.text.JTextComponent;import Tools.ConnDB;public class addInterface implements Action
6、Listener JFrame frame;JPanel p1,p2,p3;JLabel l1,l2,l3,l4;JTextField t1,t2,t3,t4;JButton last,next,enter,cancel,delete;public addInterface()frame = new JFrame("增加/修改");l1 = new JLabel("圖書編號");t1 = new JTextField(10);l2 = new JLabel("書本名稱");t2 = new JTextField(10);l3 = ne
7、w JLabel("定價 ");t3 = new JTextField(10);l4 = new JLabel("出版社 ");t4 = new JTextField(10);p1 = new JPanel();p1.add(l1);p1.add(t1);p1.add(l2);p1.add(t2);p2 = new JPanel();p2.add(l3);p2.add(t3);p2.add(l4);p2.add(t4);p3=new JPanel();last = new JButton("上一條");next = new JButt
8、on("下一條");enter = new JButton("確認");delete = new JButton("刪除");cancel = new JButton("取消");p3.add(last);p3.add(next);p3.add(enter);p3.add(cancel);p3.add(delete);enter.addActionListener(this);cancel.addActionListener(this);frame.add(BorderLayout.NORTH,p1);frame.
9、add(BorderLayout.CENTER,p2);frame.add(BorderLayout.SOUTH,p3);frame.setVisible(true);frame.setSize(500, 150);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);/*public static void main(String args)new addInterface();*/Overridepublic void actionPerformed(ActionEvent e)
10、/ TODO Auto-generated method stubif(e.getSource()=cancel)frame.dispose();if(e.getSource()=enter)ConnDB c=new ConnDB();String sql = "insert library values('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"
11、;')"SuppressWarnings("unused")int rs = c.update(sql);String rowValues= t1.getText(),t2.getText(),t3.getText(),t4.getText();InterfaceMain.tablemodel.addRow(rowValues);package Library.Management.System;/import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.Action
12、Listener;import java.sql.ResultSet;import javax.swing.*;import Tools.ConnDB;public class selInterface implements ActionListener JFrame frame;JPanel p1,p2,p3,p4,p5,p6;JLabel l1,l2,l3;JRadioButton bh,mc,cbs;ButtonGroup g;JTextField t1,t2,t3;JButton enter,cancel;JTextArea jt;JScrollPane scrollPane;publ
13、ic selInterface()frame = new JFrame("查詢");bh = new JRadioButton();bh.addActionListener(this);l1 = new JLabel("圖書編號");t1 = new JTextField(10);mc = new JRadioButton();mc.addActionListener(this);l2 = new JLabel("書本名稱");t2 = new JTextField(10);cbs = new JRadioButton();cbs.a
14、ddActionListener(this);l3 = new JLabel(" 出 版 社 ");t3 = new JTextField(10);t1.setEditable(false);t2.setEditable(false);t3.setEditable(false);g = new ButtonGroup();g.add(bh);g.add(mc);g.add(cbs);p1 = new JPanel(); p1.add(bh);p1.add(l1);p1.add(t1);p2 = new JPanel(); p2.add(mc);p2.add(l2);p2.a
15、dd(t2);p3 = new JPanel(); p3.add(cbs);p3.add(l3);p3.add(t3);p4 = new JPanel();enter = new JButton("確定");cancel = new JButton("取消");enter.addActionListener(this);cancel.addActionListener(this);p4.add(enter);p4.add(cancel);p5 = new JPanel();jt=new JTextArea(10,20);jt.setEditable(fa
16、lse);scrollPane =new JScrollPane(jt);p5.add(scrollPane);p6 = new JPanel();/p6.setLayout(new GridLayout(5,1);p6.add(p1);p6.add(p2);p6.add(p3);p6.add(p5);p6.add(p4);frame.add(p6);frame.setVisible(true);frame.setSize(350, 400);frame.setResizable(false);frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_C
17、LOSE);public static void main(String args)new selInterface();Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stubif(bh.isSelected()t1.setEditable(true);t2.setEditable(false);t3.setEditable(false);if(mc.isSelected()t1.setEditable(false);t2.setEditable(true);t3.setEdita
18、ble(false);if(cbs.isSelected()t1.setEditable(false);t2.setEditable(false);t3.setEditable(true);if(e.getSource()=enter)String sql=null;ConnDB con=new ConnDB();sql = "SELECT * FROM library where 圖書編號='"+t1.getText()+"' or 書本名稱='"+t2.getText()+"' or '"+
19、t3.getText()+"'=出版社"ResultSet rs = con.select(sql);String tempData = new String4;try while (rs.next() for (int i = 0; i < 4; i+) tempDatai = rs.getString(i + 1);jt.append(tempDatai+" ");jt.append("n"); catch (Exception e2) / TODO: handle exceptionif(e.getSource()
20、=cancel)frame.dispose();package Library.Management.System;import java.awt.*;import java.awt.event.*;import java.sql.*;import java.util.Vector;import javax.swing.*;import javax.swing.table.DefaultTableModel;import Tools.ConnDB;public class InterfaceMain implements ActionListenerJFrame frame;JPanel p1
21、,p2,p3;JButton add,sel,del,exit;JTable table;static DefaultTableModel tablemodel;JScrollPane scrollPane;Connection con;public InterfaceMain()/主界面和四個按鈕還有監(jiān)控按鈕(北部)frame = new JFrame("圖書管理系統(tǒng)");p1 = new JPanel();add = new JButton("增加");sel = new JButton("查詢");del = new JButt
22、on("刪除");exit = new JButton("退出");p1.add(add);p1.add(sel);p1.add(del);p1.add(exit);add.addActionListener(this);sel.addActionListener(this);del.addActionListener(this);exit.addActionListener(this);/分割線(中部)p2 =new JPanel();JSeparator js=new JSeparator();js.setPreferredSize(new Dime
23、nsion(1000,1);p2.add(js);/表格columnName是第一列的列名 tableValues是表格內(nèi)容(南部)Vector<String> columnName=new Vector<String>();columnName.add("圖書編號");columnName.add("書名");columnName.add("定價");columnName.add("出版社");Vector<Vector<String>> tableValue=ne
24、w Vector<Vector<String>>();ConnDB c=new ConnDB();String sql = "SELECT * FROM library"ResultSet rs = c.select(sql);try while (rs.next() Vector<String> row=new Vector<String>();String data = new String4;for (int i = 0; i < 4; i+) datai = rs.getString(i+1);/System.o
25、ut.println(datai);row.add(datai);tableValue.add(row); catch (Exception e) / TODO: handle exceptiontablemodel=new DefaultTableModel(tableValue,columnName);table = new JTable(tablemodel);table.addMouseListener(new MouseListener()Overridepublic void mouseClicked(MouseEvent e) int row = table.getSelecte
26、dRow();SuppressWarnings("unused")Object o=tablemodel.getValueAt(row, 0);Overridepublic void mousePressed(MouseEvent e) Overridepublic void mouseReleased(MouseEvent e) Overridepublic void mouseEntered(MouseEvent e) Overridepublic void mouseExited(MouseEvent e) );scrollPane = new JScrollPane
27、(table);p3 = new JPanel();p3.add(scrollPane);/設(shè)置整體面板屬性frame.add(BorderLayout.NORTH,p1);frame.add(BorderLayout.CENTER,p2);frame.add(BorderLayout.SOUTH,p3);frame.setVisible(true);frame.setSize(500, 500);frame.setResizable(false);frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);/主方法public
28、static void main(String args)new InterfaceMain();/四個按鈕的時間處理Overridepublic void actionPerformed(ActionEvent e) / TODO Auto-generated method stubif(e.getSource()=add)new addInterface();if(e.getSource()=sel)new selInterface();if(e.getSource()=del)int n=JOptionPane.showConfirmDialog(null, "是否刪除?&qu
29、ot;, "注意!",JOptionPane.YES_NO_OPTION );System.out.println(n);if(n=0)int row=table.getSelectedRow();Object bh= tablemodel.getValueAt(row, 0); ConnDB con = new ConnDB(); String sql = "Delete FROM library where 圖書編號="+bh; con.update(sql); tablemodel.removeRow(table.getSelectedRow();
30、elseSystem.out.println("取消");if(e.getSource()=exit)System.exit(0);package Library.Management.System;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import javax.swing.text.JTextComponent;import Tools.ConnDB;public class addInter
31、face implements ActionListener JFrame frame;JPanel p1,p2,p3;JLabel l1,l2,l3,l4;JTextField t1,t2,t3,t4;JButton last,next,enter,cancel,delete;public addInterface()frame = new JFrame("增加/修改");l1 = new JLabel("圖書編號");t1 = new JTextField(10);l2 = new JLabel("書本名稱");t2 = new
32、JTextField(10);l3 = new JLabel("定價 ");t3 = new JTextField(10);l4 = new JLabel("出版社 ");t4 = new JTextField(10);p1 = new JPanel();p1.add(l1);p1.add(t1);p1.add(l2);p1.add(t2);p2 = new JPanel();p2.add(l3);p2.add(t3);p2.add(l4);p2.add(t4);p3=new JPanel();last = new JButton("上一條");next = new JButton("下一條&qu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 氣候變化下農(nóng)業(yè)生態(tài)系統(tǒng)的適應(yīng)性調(diào)整研究進展
- 物聯(lián)網(wǎng)技術(shù)在智能家居生態(tài)圈的應(yīng)用前景
- 國慶節(jié)秋天主題活動方案
- 現(xiàn)代辦公樓電力維護成本深度剖析
- 現(xiàn)代物流技術(shù)與醫(yī)療行業(yè)互補與共進
- Unit 4 Friends Forever Understanding ideas 說課稿-2024-2025學年高中英語外研版(2019)必修第一冊001
- 2023八年級物理上冊 第四章 在光的世界里第6節(jié) 神奇的眼睛說課稿(新版)教科版
- 6《觀察土壤》說課稿-2023-2024學年科學四年級下冊教科版
- 2023二年級語文上冊 第八單元 24 風娃娃說課稿 新人教版
- 18《文言文二則 鐵杵成針》(說課稿)2023-2024學年-統(tǒng)編版四年級語文下冊
- 北京地鐵13號線
- 塑料成型模具設(shè)計(第2版)江昌勇課件1-塑料概述
- 產(chǎn)業(yè)園EPC總承包工程項目施工組織設(shè)計
- 方形補償器計算
- 為加入燒火佬協(xié)會致辭(7篇)
- 兒科重癥監(jiān)護病房管理演示文稿
- 甲基異丁基甲酮化學品安全技術(shù)說明書
- 條形基礎(chǔ)的平法識圖課件
- 秘書實務(wù)完整版課件全套ppt教程
- 新版神經(jīng)系統(tǒng)疾病的病史采集和體格檢查ppt
- 義務(wù)教育《歷史》課程標準(2022年版)
評論
0/150
提交評論