日期:2014-05-20 浏览次数:20781 次
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("数据库连接失败"); } } }