Java實現OracleDatabase Backup,oracleDatabase Backup

來源:互聯網
上載者:User

Java實現OracleDatabase Backup,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失敗!!!");}}}


問各位:怎使用java實現Oracle資料庫的備份

java.lang.Runtime

Processexec(String command)

Executes the specified string command in a separate process.

調用oracle的exp/imp命令,命令的用法,百度吧,很多的
 
用java代碼實現Oracle資料庫的備份與恢複(儲存為dmp或sql)

備份:發送sql給mssqlserver:
backup database <your database name> to disk='備份檔案名' with init
注意: 1.備份檔案名必須為絕對路徑,
2.備份檔案只能是mssqlserver所在的機器上的路徑, mssql支援備份到網路位置。

恢複:
restore database <your database name> from disk='備份檔案名' with replace
要注意的是執行restore database時,要恢複的資料庫必須沒有任何用戶端串連,包括自身(發起restore database命令的串連)。發使用restore,可以串連到master庫,然後再發送restore命令。
否則,一定失敗。

在jsp中如何用呢
-------------------------------------------------------------------------------------- 你用這個了!
<%
先要串連上Connection對象!
就是要先和資料庫建立起串連
然後在jsp頁面中直接用我這樣的語句就可以了
try{
String sql="backup database xncsims to disk='d:\\xncback.dat'";

st=con.createStatement();

rs=st.executeQuery(sql);

}
catch(SQLException e){ System.out.println(e.toString());}
catch(Exception e){ System.out.println(e.toString());}

%>

rs=st.executeQuery(sql);
這裡就是把你的SQL語句發到資料庫執行

另有一篇論文供參考
www.cqvip.com/...117188
 

相關文章

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.