sqlserver2000备份数据库
时间:2011-06-15 来源:﹎"該變ゾ
public boolean bankUpDataBase(String filePath) throws Exception{
DBManager db = DBManager.getInstance();
String qrySQL = " USE master select Count(phyname) from master..sysdevices where name= \'backupBank\' ";
ResultSet rs = db.executeQuery(qrySQL);
if (rs.getInt(0)>0){
String sql = "USE master exec sp_dropdevice \'backupBank\' ";
PreparedStatement pstmt = db.getCon().prepareStatement(sql);
pstmt.executeUpdate();
}
String SQL = "USE master "+
"EXEC sp_addumpdevice \'disk\', \'backupBank\',\'"+ filePath+ "\' "+
"BACKUP DATABASE bank TO backupBank ";
try{
PreparedStatement pstmt = db.getCon().prepareStatement(SQL);
pstmt.executeUpdate();
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
USE master
EXEC sp_addumpdevice 'disk', 'backupBank','d:\backup\bank.dat'
BACKUP DATABASE bank TO backupBank
USE master
select Count(phyname) from master..sysdevices where name= 'backupBank'
USE master
exec sp_dropdevice 'backupBank'