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

📄 backupframe.java

📁 图书管理系统:用户管理
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
import java.net.*;
public class BackupFrame extends JFrame implements ActionListener{
	static final long serialVersionUID=80;
	JTextField filefield;
	JButton button;
	JButton databasebutton,logbutton;
	Connection con;
	Statement sql;
	Container container;
	JFileChooser chooser;
	Dimension screenSize;
	Toolkit tool;
	URL url;
	Image myimage;
	BackupFrame(String title,Connection con){
		super(title);
		this.con=con;
		try{
			if(con!=null){
				sql=con.createStatement();
			}
		}
		catch(SQLException e2){
			JOptionPane.showMessageDialog(null,"计算机已与服务器断开");
		}
		setResizable(false);
		setSize(400,110);
		tool=getToolkit();
		screenSize=tool.getScreenSize();
		url=getClass().getResource("/images/BACKUP.GIF");
		if(url!=null){
			setIconImage(tool.getImage(url));
		}
		container=getContentPane();
		container.setBackground(Color.ORANGE);
		container.setLayout(null);
		chooser=new JFileChooser();
		filefield=new JTextField(20);
		button=new JButton("浏览");
		button.addActionListener(this);
		databasebutton=new JButton("备份数据库");
		databasebutton.addActionListener(this);
		logbutton=new JButton("备份日志");
		logbutton.addActionListener(this);
		container.add(logbutton);
	    logbutton.setBounds(250,40,100,30);
	    container.add(databasebutton);
	    databasebutton.setBounds(50,40,100,30);
		container.add(filefield);
		filefield.setBounds(0,10,320,20);
		container.add(button);
		button.setBounds(330,8,60,24);
        validate();
		setLocation((screenSize.width-this.getSize().width)/2,(screenSize.height-this.getSize().height)/2);
		setVisible(true);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e2){
				try{
					if(sql!=null){
						sql.close();
					}
				}
				catch(SQLException e3){
					JOptionPane.showMessageDialog(null,"计算机已与服务器断开");
				}
				dispose();
			}
		});
		
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==button){
			int state=chooser.showOpenDialog(this);
			File file=chooser.getSelectedFile();
			if(file!=null&&state==JFileChooser.APPROVE_OPTION){
				filefield.setText(file.getAbsolutePath());
			}
		}
		else if(e.getSource()==databasebutton){
			if(filefield.getText().length()!=0){
				String s=filefield.getText();
				s=s.replace('\\','/');
				s="'"+s+"'";
				try{
					sql.execute("BACKUP DATABASE Library TO DISK= "+s+" WITH INIT");
					JOptionPane.showMessageDialog(this,"备份数据库成功");
				}
				catch(SQLException e3){
					JOptionPane.showMessageDialog(this,"备份数据库失败");
				}
			}
			else{
				JOptionPane.showMessageDialog(this,"请选择文件进行备份");
			}
		}
		else{
			if(filefield.getText().length()!=0){
				String s=filefield.getText();
				s=s.replace('\\','/');
				s="'"+s+"'";
				try{
					sql.execute("BACKUP LOG Library TO DISK= "+s);
					JOptionPane.showMessageDialog(this,"备份日志成功");
				}
				catch(SQLException e3){
					JOptionPane.showMessageDialog(this,"备份日志失败");
				}
			}
			else{
				JOptionPane.showMessageDialog(this,"请选择文件进行备份");
			}
		}
	}
}

⌨️ 快捷键说明

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