public boolean bankUpDataBase(String filePath) throws Exception{
DBManager db = DBManager.getInstance(); String qrySQL = " USE master select Count(phyname) cnt from master..sysdevices where name= \'backupBank\' "; ResultSet rs = db.executeQuery(qrySQL); while(rs.next()){ if (rs.getInt("cnt")>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{ File file = new File(filePath); if(file.exists()){ file.delete(); } 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'