寫一個遠端資料庫備份&還原的javabean

xuehongliang發表於2007-08-12

backup.jsp 用來輸入使用者 密碼 路徑的檔案



backup




user:

pass:

path:





backupdate.jsp
備份資料庫的檔案





backupdate

String user = request.getParameter("user");
String pass = request.getParameter("pass");
String path = request.getParameter("path");
String backupdate="";
backupdate = Backup.backup(user,pass,path);
out.print(backupdate);
%>


Backup.java
備份資料庫的java檔案
package backup;

import java.io.*;
import java.util.*;

public class Backup
{
public String backup(String user,String pass,String path)
{
try {
java.io.File dir=new java.io.File(path);
if (!dir.isDirectory()) {
String cuowu="The path is not find !!!";
return cuowu;
}
java.text.SimpleDateFormat temp = new java.text.SimpleDateFormat("yyyy-MM-dd-HHmm");
String today = temp.format(new Date() );
String filename=path+""+today+".dmp";

java.lang.Runtime rt=java.lang.Runtime.getRuntime();
java.lang.Process p=null;

p=rt.exec("exp "+user+"/"+pass+" FILE="+filename);
String chenggong="The filname is : "+filename;
return chenggong;
}
catch (Exception e) {
String geshi="user pass path";
return geshi;
}
}
}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/800861/viewspace-950726/,如需轉載,請註明出處,否則將追究法律責任。

相關文章