⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query_jieyue.java

📁 图书管理系统
💻 JAVA
字号:
/* * Query_Jieyue.java * * Created on 2008年5月19日, 上午10:07 */import java.sql.*;import javax.swing.JOptionPane;/** * * @author  Administrator */public class Query_Jieyue extends javax.swing.JDialog {        /** Creates new form Query_Jieyue */    public Query_Jieyue(java.awt.Frame parent, boolean modal) {         super(parent, modal);        initComponents();        this.setTitle("借阅信息查询");        this.setResizable(false);    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jPanel1 = new javax.swing.JPanel();        jLabel1 = new javax.swing.JLabel();        jtxtLibCard = new javax.swing.JTextField();        jLabel2 = new javax.swing.JLabel();        jtxtISBN = new javax.swing.JTextField();        jLabel3 = new javax.swing.JLabel();        jtxtBorrowTime = new javax.swing.JTextField();        jLabel4 = new javax.swing.JLabel();        jLabel5 = new javax.swing.JLabel();        jbtnQuery = new javax.swing.JButton();        jlabelMsg = new javax.swing.JLabel();        jcmbIndex = new javax.swing.JComboBox();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        jLabel1.setText("借书证号:");        jLabel2.setText("ISBN:");        jLabel3.setText("借出时间:");        jLabel4.setText("(格式:2000-11-11)");        jLabel5.setText("索书号:");        jbtnQuery.setText("查询");        jbtnQuery.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jbtnQueryActionPerformed(evt);            }        });        jlabelMsg.setFont(new java.awt.Font("宋体", 0, 14));        jcmbIndex.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jcmbIndexActionPerformed(evt);            }        });        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()                        .addGap(20, 20, 20)                        .addComponent(jlabelMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()                        .addGap(36, 36, 36)                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)                                .addGroup(jPanel1Layout.createSequentialGroup()                                    .addComponent(jLabel2)                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                                    .addComponent(jtxtISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))                                .addGroup(jPanel1Layout.createSequentialGroup()                                    .addComponent(jLabel1)                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                    .addComponent(jtxtLibCard)))                            .addGroup(jPanel1Layout.createSequentialGroup()                                .addComponent(jLabel5)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(jcmbIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(jbtnQuery))                            .addGroup(jPanel1Layout.createSequentialGroup()                                .addComponent(jLabel3)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(jtxtBorrowTime, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                .addComponent(jLabel4)))                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addGap(35, 35, 35)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel1)                    .addComponent(jtxtLibCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addGap(18, 18, 18)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel2)                    .addComponent(jtxtISBN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel3)                    .addComponent(jtxtBorrowTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel4))                .addGap(18, 18, 18)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel5)                    .addComponent(jbtnQuery)                    .addComponent(jcmbIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(jlabelMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);        pack();    }// </editor-fold>//GEN-END:initComponents    public void Empty(){        try{            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");        }catch(ClassNotFoundException ex)        {            jlabelMsg.setText("SQL错:"+ex.getMessage());        }        try {            String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=sources\\data.mdb;pwd=shujuyuan";            Connection con=DriverManager.getConnection(url);            Statement st=con.createStatement();                        ResultSet res=st.executeQuery("select suoshuNo from jy");            jcmbIndex.removeAllItems();            while(res.next())                jcmbIndex.addItem(res.getString("suoshuNo"));            try {                if (st != null) { st.close(); }            } catch (SQLException sQLException) { }        }catch(Exception e){            JOptionPane.showConfirmDialog(null,"找不到数据库驱动程序!","Warning",JOptionPane.CLOSED_OPTION,JOptionPane.WARNING_MESSAGE);            this.setVisible(false);        }        jtxtLibCard.setText("");        jtxtISBN.setText("");        jtxtBorrowTime.setText("");        jcmbIndex.setSelectedIndex(0);        jlabelMsg.setText("选择索书号,然后点击查询。");        jtxtLibCard.setEnabled(false);        jtxtISBN.setEnabled(false);        jtxtBorrowTime.setEnabled(false);    }        private void jbtnQueryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnQueryActionPerformed        // TODO add your handling code here:        jtxtLibCard.setText("");        jtxtISBN.setText("");        jtxtBorrowTime.setText("");        String flag="",ss="";        try{            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");        }catch(ClassNotFoundException ex)        {            jlabelMsg.setText("SQL错:"+ex.getMessage());        }        try {            String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=sources\\data.mdb;pwd=shujuyuan";            Connection con = DriverManager.getConnection(url);            PreparedStatement ps = con.prepareStatement("select * from jy where suoshuNo=?");            ss = new String((String) jcmbIndex.getSelectedItem());            if (ss.length() < 1) {                throw new ArrayIndexOutOfBoundsException();            }            ps.setString(1, ss);            ResultSet rs = ps.executeQuery();            while(rs.next()){                flag=new String(rs.getString("libCard"));                jtxtLibCard.setText(flag);                jtxtISBN.setText(rs.getString("ISBN"));                jtxtBorrowTime.setText(rs.getString("borrowTime").substring(0,10));            }            if(flag.length()<1) throw new ArrayIndexOutOfBoundsException();            try {                if(ps!=null) ps.close();                if(rs!=null) rs.close();                if(con!=null) con.close();            } catch (SQLException sQLException) { }            jlabelMsg.setText("查询成功!");             jtxtLibCard.setEnabled(true);            jtxtISBN.setEnabled(true);            jtxtBorrowTime.setEnabled(true);        } catch (ArrayIndexOutOfBoundsException e) {            if(ss.length()<1) jlabelMsg.setText("请选择索书号!");            else if(flag.length()<1) jlabelMsg.setText("没有此号借阅记录!");        }        catch(Exception e){            jlabelMsg.setText("查询失败!(可能连接数据库失败)");        }    }//GEN-LAST:event_jbtnQueryActionPerformed    private void jcmbIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbIndexActionPerformed        // TODO add your handling code here:        jtxtLibCard.setText("");        jtxtISBN.setText("");        jtxtBorrowTime.setText("");        jlabelMsg.setText("选择索书号,然后点击添加。");        jtxtLibCard.setEnabled(false);        jtxtISBN.setEnabled(false);        jtxtBorrowTime.setEnabled(false);    }//GEN-LAST:event_jcmbIndexActionPerformed        /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                Query_Jieyue dialog = new Query_Jieyue(new javax.swing.JFrame(), true);                dialog.addWindowListener(new java.awt.event.WindowAdapter() {                    public void windowClosing(java.awt.event.WindowEvent e) {                        System.exit(0);                    }                });                dialog.setVisible(true);            }        });    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JPanel jPanel1;    private javax.swing.JButton jbtnQuery;    private javax.swing.JComboBox jcmbIndex;    private javax.swing.JLabel jlabelMsg;    private javax.swing.JTextField jtxtBorrowTime;    private javax.swing.JTextField jtxtISBN;    private javax.swing.JTextField jtxtLibCard;    // End of variables declaration//GEN-END:variables    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -