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

📄 backuplogs.java

📁 实现JSP开发的BBS源码
💻 JAVA
字号:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//数据库日志备份功能 

public class backupLogs extends JFrame implements ActionListener{
	//定义组件
	private JLabel inputPathLabel=new JLabel("输入要保存日志的路径及文件名:");
	private JTextField inputPath=new JTextField(30);
	private JButton backupButton=new JButton("备份");
	private JLabel noticeLabel=new JLabel("注意:路径要存在,文件保存类型为.logs");
	
	//定义数据库操作所用变量
	Statement st=null;
	ResultSet rs=null;
	Connection con=null;
	private boolean flag=true;
	
    //构造方法
    
    public backupLogs(){
    	setTitle("数据库日志备份");
    	setSize(350,250);
    	setLocation(350,400);
    	setResizable(false);
    	//创建面板
    	Container c=getContentPane();
    	c.setLayout(null);
    	//提示输入路径区
    	c.add(inputPathLabel);
    	inputPathLabel.setFont(new Font("华文行楷",Font.BOLD,20));
    	inputPathLabel.setBounds(10,30,320,40);
    	
    	//添加输入路径区
    	c.add(inputPath);
    	inputPath.setBounds(30,90,200,40);
    	inputPath.setText("g:\\BSMS\\backup\\logs\\BSMS.logs");
    	
    	//备份提交按钮
    	c.add(backupButton);
    	backupButton.setBounds(245,90,70,40);
    	backupButton.addActionListener(this);
    	
    	//注意:
    	c.add(noticeLabel);
    	noticeLabel.setFont(new Font("华文新魏",Font.PLAIN, 18));
    	noticeLabel.setBounds(10,140,330,40);
    	noticeLabel.setForeground(Color.red);
    	show();
    	
    }
    
    //事件监听
    public void actionPerformed(ActionEvent ae){
    	flag=true;
    	String getPath=inputPath.getText().trim();
    	if(getPath.equals("")==true){
    		JOptionPane.showMessageDialog(null,"请输入要存放备份日志文件的路径");
    	    flag=false;
    	}
    	String command="backup log BSMS to disk='"+getPath+"' with init";
    	try{
    		st=connectDB.conDB();//连接数据库
 		   	con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=BSMS","sa","5201314");
    		if(flag){
    			st.executeUpdate(command);//备份数据库
        		JOptionPane.showMessageDialog(null,"数据库日志成功备份");
    		}
    	}catch(SQLException ex){
    		if(ex!=null){
    			JOptionPane.showMessageDialog(null,ex);
    			flag=false;
    		}
    	}
    closeDB.closeDB(st,con);
    }
    public static void main(String args[]){
    	new backupLogs();
    }	

}

⌨️ 快捷键说明

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