日期:2014-05-20  浏览次数:20781 次

关于数据库备份!!!!
java中如何实现对数据库的备份,好象是什么backup语句?请给出详细代码

------解决方案--------------------
代码如下
Java code
import java.sql.*;

public class TestSql2000_bak
{
    public static void main(String[] args)
    {
        try
        {
            String sql = "USE [color=#FF0000]mydatabase [/color]"+
            "EXEC sp_addumpdevice 'disk','[color=#00FF00]testBAK[/color]','C:\\tttt\\bak.dat' "+
            "BACKUP DATABASE rbac TO [color=#00FF00]testBAK[/color]";
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
                    .newInstance();
            System.out.println("数据库驱动程序注册成功!");
            String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=northwind";
            String user = "sa";
            String password = "pwd";
            Connection conn = DriverManager.getConnection(url, user, password);
            System.out.println("数据库连接成功");
            Statement stmt = conn.createStatement();
            stmt.execute(sql);
            System.out.println("备份成功");
        } catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("数据库连接失败");
        }
    }
}