sqlserver2000备份数据库

     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'

posted @ 2011-06-15 17:07  ﹎"該變ゾ  阅读(211)  评论(0编辑  收藏  举报