最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)簡(jiǎn)單的圖書(shū)借閱系統(tǒng)

 更新時(shí)間:2022年03月12日 16:20:38   作者:西蘭先森  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡(jiǎn)單的圖書(shū)借閱系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)簡(jiǎn)單圖書(shū)借閱系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

直接看代碼:

package ttt;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
public class Labmsys extends JFrame{
? ? ? ? JTable booktable=null;
? ? ? ? static DefaultTableModel bookmodel=null;
? ? ? ? JTable borrowtable=null;
? ? ? ? static DefaultTableModel bmodel=null;
? ? ? ? JPanel j1=new JPanel();
? ? ? ? JPanel j2=new JPanel();
? ? ? ? JPanel j3=new JPanel();
? ? ? ? JButton button1=new JButton("借書(shū)");
? ? ? ? JButton button2=new JButton("還書(shū)");

? ? public Labmsys()
? ? {
? ? ? ? this.setLayout(new BorderLayout());
? ? ? ? this.add(j1,BorderLayout.WEST);
? ? ? ? this.add(j2,BorderLayout.EAST);
? ? ? ? this.add(j3,BorderLayout.CENTER);
? ? ? ? j1.setBorder(new TitledBorder("圖書(shū)借書(shū)表"));
? ? ? ? j2.setBorder(new TitledBorder("圖書(shū)庫(kù)存表"));
? ? ? ? this.booktable=bookIn();
? ? ? ? this.borrowtable=borrowIn();
? ? ? ? JScrollPane ?jsp1=new JScrollPane(borrowtable);
? ? ? ? JScrollPane ?jsp2=new JScrollPane(booktable);
? ? ? ? j1.add(jsp1);
? ? ? ? j2.add(jsp2);
? ? ? ? j3.add(button1);
? ? ? ? j3.add(button2);
? ? ? ? //添加借書(shū)監(jiān)聽(tīng)器
? ? ? ? button1.addActionListener(new ActionListener()
? ? ? ? {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void actionPerformed(ActionEvent e) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? int rowNum=booktable.getSelectedRow();
? ? ? ? ? ? ? ? System.out.println(rowNum);
? ? ? ? ? ? ? ? if(rowNum>=0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? String isbn=booktable.getValueAt(rowNum, 0).toString();
? ? ? ? ? ? ? ? ? ? System.out.println(isbn);
? ? ? ? ? ? ? ? ? ? int count=Integer.parseInt((String) booktable.getValueAt(rowNum, 2));
? ? ? ? ? ? ? ? ? ? String s=JOptionPane.showInputDialog("請(qǐng)輸入學(xué)號(hào)");
? ? ? ? ? ? ? ? ? ? if(count<=0)
? ? ? ? ? ? ? ? ? ? ? ? JOptionPane.showMessageDialog(null,"圖書(shū)庫(kù)存不足");
? ? ? ? ? ? ? ? ? ? else if (null==s)
? ? ? ? ? ? ? ? ? ? ? ? JOptionPane.showMessageDialog(null,"請(qǐng)輸入學(xué)號(hào)");
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? if(borrowBook(isbn,s))
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("yes");
? ? ? ? ? ? ? ? ? ? ? ? ? ? JOptionPane.showMessageDialog(null,"successful!");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else JOptionPane.showMessageDialog(null,"Wrong!");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else JOptionPane.showMessageDialog(null,"Choose book!");

? ? ? ? ? ? }
? ? ? });
? ? ? ? //添加還書(shū)監(jiān)聽(tīng)器
? ? ? ? button2.addActionListener(new ActionListener()
? ? ? ? {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void actionPerformed(ActionEvent e) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? int rowNum=borrowtable.getSelectedRow();
? ? ? ? ? ? ? ? System.out.println(rowNum);
? ? ? ? ? ? ? ? if(rowNum>=0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? String isbn=borrowtable.getValueAt(rowNum, 2).toString();
? ? ? ? ? ? ? ? ? ? String tablexh = borrowtable.getValueAt(rowNum, 1).toString();
? ? ? ? ? ? ? ? ? ? System.out.println(isbn);
? ? ? ? ? ? ? ? ? ? String xh=JOptionPane.showInputDialog("請(qǐng)輸入學(xué)號(hào)");
? ? ? ? ? ? ? ? ? ? if (!xh.equals(tablexh))
? ? ? ? ? ? ? ? ? ? ? ? JOptionPane.showMessageDialog(null,"學(xué)號(hào)不正確");
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? if(returnBook(isbn))
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? JOptionPane.showMessageDialog(null,"successful!");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else JOptionPane.showMessageDialog(null,"Wrong!");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else JOptionPane.showMessageDialog(null,"Choose book!");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? });

? ? }

? ? public boolean borrowBook(String isbn, String s) {
? ? ? ? ? ? ? ? int xh = Integer.parseInt(s);
? ? ? ? ? ? ? ? int isbn2 =Integer.parseInt(isbn);
? ? ? ? ? ? ? ? System.out.println("學(xué)號(hào):"+xh);
? ? ? ? boolean b=false;
? ? ? ? String driver="com.mysql.jdbc.Driver";
? ? ? ? String url="jdbc:mysql://localhost:3306/test";
? ? ? ? String user="root";
? ? ? ? String password="123456";

? ? ? ? Connection conn=null;
? ? ? ? Statement stmt=null;

? ? ? ? try { ?
? ? ? ? ? ? ? ?Class.forName(driver);?
? ? ? ? ? ? ? ?conn = DriverManager.getConnection(url, user, password); ?
? ? ? ? ? ? ? ?stmt = conn.createStatement(); ?

? ? ? ? ? ? ? ?System.out.println("isbn:"+isbn);
? ? ? ? ? ? ? ?conn.setAutoCommit(false);
? ? ? ? ? ? ? ?String sql1 = "update book set count=count-1 where isbn='"+isbn2+"'";
? ? ? ? ? ? ? ?String sql2 = "insert into borrow(xh,isbn) values('"+xh+"','"+isbn2+"')";
? ? ? ? ? ? ? ?stmt.executeUpdate(sql1);

? ? ? ? ? ? ? ?stmt.executeUpdate(sql2);
? ? ? ? ? ? ? ?System.out.println("isbn2:"+isbn2);
? ? ? ? ? ? ? ?//stmt = (PreparedStatement) conn.prepareStatement("update book set count=count-1 where isbn=?");

? ? ? ? ? ? ? ?conn.commit();
? ? ? ? ? ? ? ?stmt.close();
? ? ? ? ? ? ? ?conn.close();
? ? ? ? ? ? ? ?b=true;
? ? ? ? }
? ? ? ? catch (Exception e) { ?
? ? ? ? ? ? ? ?try{
? ? ? ? ? ? ? ? ? ?conn.rollback();
? ? ? ? ? ? ? ?}catch(Exception e1){e1.printStackTrace();}
? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? return b;
? ? ? ? ? ? }

? ? private boolean returnBook(String isbn) {
? ? ? ? int isbn2 =Integer.parseInt(isbn);

? ? ? ? ? ?boolean b=false;
? ? ? ? ? ?String driver="com.mysql.jdbc.Driver";
? ? ? ? ? ?String url="jdbc:mysql://localhost:3306/test";
? ? ? ? ? ?String user="root";
? ? ? ? ? ?String password="123456";


? ? ? ? ? ?Connection conn=null;
? ? ? ? ? ?Statement stmt=null;


? ? ? ? ? ?try { ?
? ? ? ? ? ? ?Class.forName(driver);?
? ? ? ? ? ? ?conn = DriverManager.getConnection(url, user, password); ?
? ? ? ? ? ? ?stmt = conn.createStatement(); ?
? ? ? ? ? ? ?conn.setAutoCommit(false);
? ? ? ? ? ? ?stmt.executeUpdate("delete from borrow where isbn='"+isbn2+"'");
? ? ? ? ? ? ?stmt.executeUpdate("update book set count=count+1 where isbn='"+isbn2+"'");
? ? ? ? ? ? ?System.out.println("還書(shū)isbn2:"+isbn2);
? ? ? ? ? ? ?conn.commit();
? ? ? ? ? ? ?stmt.close();
? ? ? ? ? ? ?conn.close();
? ? ? ? ? ? ?b=true;
? ? ? ? ? ? ?}
? ? ? ? ? ?catch (Exception e) { ?
? ? ? ? ? ? ? ?try{
? ? ? ? ? ? ? ? ? ?conn.rollback();
? ? ? ? ? ? ? ? ? ?}catch(Exception e1){e1.printStackTrace();}} ?
? ? ? ? ? ?return b;
? ? }

? ? private JTable borrowIn() {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? String []head={"id","xh","ISBN"};
? ? ? ? String [][]data=null;
? ? ? ? bookmodel=new DefaultTableModel(data,head);
? ? ? ? JTable t=new JTable(bookmodel);
? ? ? ? String driver="com.mysql.jdbc.Driver";
? ? ? ? String url="jdbc:mysql://localhost:3306/test";
? ? ? ? String user="root";
? ? ? ? String password="123456";

? ? ? ? Connection conn=null;
? ? ? ? Statement stmt=null;
? ? ? ? ResultSet rs=null;
? ? ? ? try { ?
? ? ? ? ? ? ? ?Class.forName(driver);?

? ? ? ? ? ? ? ?conn = DriverManager.getConnection(url, user, password); ?
? ? ? ? ? ? ? ?stmt = conn.createStatement(); ?
? ? ? ? ? ? ? ?rs=stmt.executeQuery("select * from borrow");?
? ? ? ? ? ? ? ?String[] row=new String[3];
? ? ? ? ? ? ? ?while(rs.next()){
? ? ? ? ? ? ? ?row[0]=rs.getString(1);
? ? ? ? ? ? ? ?row[1]=rs.getString(2);
? ? ? ? ? ? ? ?row[2]=rs.getString(3);
? ? ? ? ? ? ? ?bookmodel.addRow(row);
? ? ? ? ? ? ? ?bookmodel.fireTableDataChanged(); }
? ? ? ? ? ? ? ?rs.close();
? ? ? ? ? ? ? ?stmt.close();
? ? ? ? ? ? ? ?conn.close();}

? ? ? ? catch (Exception e) { ?
? ? ? ? ? ? ? ?// TODO Auto-generated catch block ? ??
? ? ? ? ? ? ? ?System.out.println(e); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? return t;
? ? }


? ? public ?JTable bookIn() {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? String []head={"ISBN","name","count"};
? ? ? ? String [][]data=null;
? ? ? ? bmodel=new DefaultTableModel(data,head);
? ? ? ? JTable t=new JTable(bmodel);
? ? ? ? String driver="com.mysql.jdbc.Driver";
? ? ? ? String url="jdbc:mysql://localhost:3306/test";
? ? ? ? String user="root";
? ? ? ? String password="123456";

? ? ? ? Connection conn=null;
? ? ? ? Statement stmt=null;
? ? ? ? ResultSet rs=null;
? ? ? ? try { ?
? ? ? ? ? ? ? ?Class.forName(driver);?

? ? ? ? ? ? ? ?conn = DriverManager.getConnection(url, user, password); ?
? ? ? ? ? ? ? ?stmt = conn.createStatement(); ?
? ? ? ? ? ? ? ?rs=stmt.executeQuery("select * from book");?
? ? ? ? ? ? ? ?String[] row=new String[3];
? ? ? ? ? ? ? ?while(rs.next()){
? ? ? ? ? ? ? ?row[0]=rs.getString(1);
? ? ? ? ? ? ? ?row[1]=rs.getString(2);
? ? ? ? ? ? ? ?row[2]=rs.getString(3);
? ? ? ? ? ? ? ?bmodel.addRow(row);
? ? ? ? ? ? ? ?bmodel.fireTableDataChanged(); }
? ? ? ? ? ? ? ?rs.close();
? ? ? ? ? ? ? ?stmt.close();
? ? ? ? ? ? ? ?conn.close();}

? ? ? ? catch (Exception e) { ?
? ? ? ? ? ? ? ?// TODO Auto-generated catch block ? ??
? ? ? ? ? ? ? ?System.out.println(e); ?
? ? ? ? ? ? ? }
? ? ? ? return t; ?
? ? }


? ? public static void main(String[] args) {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? Labmsys n=new Labmsys();?
? ? ? ? n.setTitle("圖書(shū)借閱管理系統(tǒng)");
? ? ? ? n.setSize(1000,500);
? ? ? ? n.setLocationRelativeTo(null);
? ? ? ? n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
? ? ? ? n.setVisible(true);
? ? }

}

數(shù)據(jù)庫(kù):

--
-- Table structure for table `book`
--

DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
? `ISBN` int(11) NOT NULL,
? `name` varchar(50) NOT NULL,
? `count` int(11) default NULL,
? PRIMARY KEY ?(`ISBN`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `book`
--

LOCK TABLES `book` WRITE;
/*!40000 ALTER TABLE `book` DISABLE KEYS */;
INSERT INTO `book` VALUES (662530,'c#',9),(662545,'python',12),(663520,'c++',6),(663548,'java',8);
/*!40000 ALTER TABLE `book` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `borrow`
--

DROP TABLE IF EXISTS `borrow`;
CREATE TABLE `borrow` (
? `id` int(11) NOT NULL auto_increment,
? `xh` int(11) NOT NULL,
? `isbn` int(11) NOT NULL,
? PRIMARY KEY ?(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `borrow`
--

LOCK TABLES `borrow` WRITE;
/*!40000 ALTER TABLE `borrow` DISABLE KEYS */;
INSERT INTO `borrow` VALUES (1006,123456,662545),(1007,456789,663520),(1009,789456,662530),(1010,741852,662530);

運(yùn)行結(jié)果顯示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot 將多個(gè)Excel打包下載的實(shí)現(xiàn)示例

    SpringBoot 將多個(gè)Excel打包下載的實(shí)現(xiàn)示例

    本文主要介紹了SpringBoot 將多個(gè)Excel打包下載的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12
  • 詳解JAVA中的Collection接口和其主要實(shí)現(xiàn)的類(lèi)

    詳解JAVA中的Collection接口和其主要實(shí)現(xiàn)的類(lèi)

    這篇文章主要介紹了JAVA中的Collection接口和其主要實(shí)現(xiàn)的類(lèi),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • 使用@Value為靜態(tài)變量導(dǎo)入并使用導(dǎo)入的靜態(tài)變量進(jìn)行初始化方式

    使用@Value為靜態(tài)變量導(dǎo)入并使用導(dǎo)入的靜態(tài)變量進(jìn)行初始化方式

    這篇文章主要介紹了使用@Value為靜態(tài)變量導(dǎo)入并使用導(dǎo)入的靜態(tài)變量進(jìn)行初始化方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • SpringBoot中各種Controller的寫(xiě)法

    SpringBoot中各種Controller的寫(xiě)法

    這篇文章主要介紹了SpringBoot中各種Controller的寫(xiě)法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Java中使用ConcurrentHashMap實(shí)現(xiàn)線程安全的Map

    Java中使用ConcurrentHashMap實(shí)現(xiàn)線程安全的Map

    在Java中,ConcurrentHashMap是一種線程安全的哈希表,可用于實(shí)現(xiàn)多線程環(huán)境下的Map操作。它支持高并發(fā)的讀寫(xiě)操作,通過(guò)分段鎖的方式實(shí)現(xiàn)線程安全,同時(shí)提供了一些高級(jí)功能,比如迭代器弱一致性和批量操作等。ConcurrentHashMap在高并發(fā)場(chǎng)景中具有重要的應(yīng)用價(jià)值
    2023-04-04
  • SpringBoot?項(xiàng)目打成?jar后加載外部配置文件的操作方法

    SpringBoot?項(xiàng)目打成?jar后加載外部配置文件的操作方法

    這篇文章主要介紹了SpringBoot?項(xiàng)目打成?jar后加載外部配置文件的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • 一文讀懂Spring Bean的生命周期

    一文讀懂Spring Bean的生命周期

    今天我們來(lái)說(shuō)一說(shuō) Spring Bean 的生命周期,小伙伴們應(yīng)該在面試中經(jīng)常遇到,這是正常現(xiàn)象,本文讓更多的小伙伴們可以輕松的讀懂 Spring Bean 的生命周期
    2023-03-03
  • java并發(fā)之synchronized

    java并發(fā)之synchronized

    這篇文章主要介紹了java并發(fā)關(guān)鍵字synchronized,包括內(nèi)容synchronized的使用、synchronized背后的Monitor、synchronized保證可見(jiàn)性和防重排序、使用synchronized注意嵌套鎖定,具體內(nèi)容請(qǐng)看下面文章吧
    2021-10-10
  • Java設(shè)計(jì)模式之原型設(shè)計(jì)示例詳解

    Java設(shè)計(jì)模式之原型設(shè)計(jì)示例詳解

    這篇文章主要為大家詳細(xì)介紹了Java的原型設(shè)計(jì)模式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • JAVA HashSet和TreeSet 保證存入元素不會(huì)重復(fù)的操作

    JAVA HashSet和TreeSet 保證存入元素不會(huì)重復(fù)的操作

    這篇文章主要介紹了JAVA HashSet和TreeSet 保證存入元素不會(huì)重復(fù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09

最新評(píng)論

通州市| 喜德县| 桐城市| 吉水县| 竹山县| 扎鲁特旗| 塘沽区| 六安市| 都安| 大港区| 射阳县| 古蔺县| 班戈县| 弥勒县| 黄平县| 平利县| 济宁市| 邯郸县| 三河市| 玉树县| 南投县| 开远市| 宁化县| 卓尼县| 肃宁县| 都江堰市| 禹州市| 上蔡县| 丰原市| 洛宁县| 乌拉特前旗| 阳江市| 辉南县| 桂平市| 甘南县| 图木舒克市| 灵寿县| 新沂市| 怀来县| 景泰县| 利津县|