d_restore.java
来自「图书管理系统」· Java 代码 · 共 137 行
JAVA
137 行
/*
* D_restore.java
*
* Created on 2007年6月25日, 下午3:59
*/
package 图书管理系统;
import javax.swing.*;
import java.sql.*;
public class D_restore extends javax.swing.JFrame {
/** Creates new form D_restore */
public D_restore() {
initComponents();
con=connect.getcon();
this.setTitle("数据库还原");
this.setBounds(300,250,350,200);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
try{
con.close();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=master","sa","123456");
stmt=con.createStatement();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
/** 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_restore = new javax.swing.JButton();
B_cancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u8bf7\u8f93\u5165\u6570\u636e\u6e90\u7684\u5168\u8def\u5f84:");
B_restore.setText("\u8fd8\u539f\u6570\u636e\u5e93");
B_restore.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B_restoreActionPerformed(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(32, 32, 32)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 143, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createSequentialGroup()
.add(B_restore)
.add(44, 44, 44)
.add(B_cancel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(48, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(80, Short.MAX_VALUE)
.add(T_path, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 167, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(59, 59, 59))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.add(22, 22, 22)
.add(T_path, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(30, 30, 30)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(B_restore)
.add(B_cancel))
.add(9, 9, 9))
);
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_restoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_restoreActionPerformed
// TODO 将在此处添加您的处理代码:
try{
PreparedStatement sql=con.prepareStatement("restore database 图书管理系统 from disk=?");
sql.setString(1,T_path.getText().trim());
sql.executeUpdate();
JOptionPane.showMessageDialog(null,"数据库还原成功");
this.setVisible(false);
}
catch(Exception ee)
{
JOptionPane.showMessageDialog(null,"数据库还原失败,请重启SQL服务器再还原数据库");
ee.printStackTrace();
}
}//GEN-LAST:event_B_restoreActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new D_restore().setVisible(true);
}
});
}
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton B_cancel;
private javax.swing.JButton B_restore;
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 + -
显示快捷键?