d_backup.java

来自「图书管理系统」· Java 代码 · 共 126 行

JAVA
126
字号
/*
 * D_backup.java
 *
 * Created on 2007年6月25日, 下午3:41
 */

package 图书管理系统;
import javax.swing.*;
import java.sql.*;

public class D_backup extends javax.swing.JFrame {
    
    /** Creates new form D_backup */
    public D_backup() {
        initComponents();
        con=connect.getcon();
        this.setTitle("数据库备份");
        this.setBounds(300,250,450,250);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    /** 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=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        T_path = new javax.swing.JTextField();
        B_backup = new javax.swing.JButton();
        B_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8bf7\u8f93\u5165\u5907\u4efd\u6587\u4ef6\u7684\u8def\u5f84:");

        B_backup.setText("\u5907\u4efd\u6570\u636e\u5e93");
        B_backup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_backupActionPerformed(evt);
            }
        });

        B_cancel.setText("\u53d6\u6d88");
        B_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_cancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(29, 29, 29)
                        .add(jLabel1)
                        .add(38, 38, 38)
                        .add(T_path, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 180, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(82, 82, 82)
                        .add(B_backup)
                        .add(68, 68, 68)
                        .add(B_cancel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(36, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(35, 35, 35)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(T_path, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .add(38, 38, 38)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(B_backup)
                    .add(B_cancel))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void B_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_cancelActionPerformed
// TODO 将在此处添加您的处理代码:
        this.setVisible(false);
    }//GEN-LAST:event_B_cancelActionPerformed

    private void B_backupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_backupActionPerformed
// TODO 将在此处添加您的处理代码:
        try{
        PreparedStatement sql=con.prepareStatement("BACKUP  DATABASE  图书管理系统  TO  DISK=?  WITH  Format");
        sql.setString(1,T_path.getText().trim());
        sql.executeUpdate();
        JOptionPane.showMessageDialog(null,"数据库备份成功");
        this.setVisible(false);
        }
         catch(Exception ee)
         {
       JOptionPane.showMessageDialog(null,"数据库备份失败,请检查您输入的路径名");
 ee.printStackTrace();
    }
    }//GEN-LAST:event_B_backupActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new D_backup().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton B_backup;
    private javax.swing.JButton B_cancel;
    private javax.swing.JTextField T_path;
    private javax.swing.JLabel jLabel1;
    // 变量声明结束//GEN-END:variables
    private Connection con;
    private Statement stmt;
}

⌨️ 快捷键说明

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