Java代碼實現向Oracle資料庫中匯入已備份的資料庫檔案
今天將很早就實現的一個OracleDatabase Backup功能粘貼出來,這個功能是在大學做階段設計時寫的:
import java.io.IOException;
/**
* Java代碼實現向Oracle資料庫中匯入已備份的資料庫檔案
*
* @author:Gaohuanjie
*/
public class OracleImportDatabase {
/**
* 向Oracle資料庫中匯入已備份的資料庫檔案
*
* @author:Gaohuanjie
* @param userName 進入資料庫所需要的使用者名稱
* @param password 進入資料庫所需要的密碼
* @param SID 使用者所在的SID
* @param fromUserName 匯入的資料檔案原來的使用者
* @param filePath 不包含副檔名的Database Backup檔案路徑
* @return 返回true表示匯入成功,返回false表示匯入失敗
*/
public static boolean importDatabase(String userName, String password, String SID, String fromUserName, String filePath)throws InterruptedException {
String toUserName = userName;
try {
Process process = Runtime.getRuntime().exec("imp " + userName + "/" + password + "@" + SID + " fromuser=" + fromUserName + " touser=" + toUserName + " file=" + filePath + ".dmp");
if (process.waitFor() == 0) {// 0 表示線程正常終止。
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public static void main(String[] args) throws InterruptedException {
if (importDatabase("gaohuanjie", "ab19890110", "orcl", "gaohuanjie", "D:\\oracledb")) {
System.out.println("資料庫成功匯入!!!");
} else {
System.out.println("資料庫匯入失敗!!!");
}
}
}
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