Java實現OracleDatabase Backup

來源:互聯網
上載者:User

Java實現OracleDatabase Backup

今天將很早就實現的一個OracleDatabase Backup功能粘貼出來,這個功能是在大學做階段設計時寫的:

import java.io.File;
import java.io.IOException;

/**
 * OracleDatabase Backup
 *
 * @author GaoHuanjie
 */
public class OracleDatabaseBackup {

 /**
  * Java代碼實現Oracle資料庫匯出
  *
  * @author GaoHuanjie
  * @param userName 進入資料庫所需要的使用者名稱
  * @param password 進入資料庫所需要的密碼
  * @param SID 使用者所在的SID
  * @param savePath 資料庫匯出檔案儲存路徑
  * @param fileName 資料庫匯出檔案檔案名稱
  * @return 返回true表示匯出成功,否則返回false。
  */
 public static boolean exportDatabaseTool(String userName, String password, String SID, String savePath, String fileName) throws InterruptedException {
  File saveFile = new File(savePath);
  if (!saveFile.exists()) {// 如果目錄不存在
   saveFile.mkdirs();// 建立檔案夾
  }
  try {
   Process process = Runtime.getRuntime().exec("exp " + userName + "/" + password + "@" + SID + " file=" + savePath + "/" + fileName + ".dmp");
   if(process.waitFor() == 0){//0 表示線程正常終止。
    return true;
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
  return false;
 }

 public static void main(String[] args) throws InterruptedException {
  if (exportDatabaseTool("gaohuanjie", "ab19890110", "orcl", "d:/BackupDatabase", "oracledb")) {
   System.out.println("資料庫成功備份!!!");
  } else {
   System.out.println("Database Backup失敗!!!");
  }
 }
}

Oracle 11g 在RedHat Linux 5.8_x64平台的安裝手冊

Linux-6-64下安裝Oracle 12C筆記

在CentOS 6.4下安裝Oracle 11gR2(x64)

Oracle 11gR2 在VMWare虛擬機器中安裝步驟

Debian 下 安裝 Oracle 11g XE R2

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.