Java implements Oracle database backup and oracle Database Backup
Today, we will paste an Oracle database backup feature that has been implemented very early. This feature was designed at the university stage:
Import java. io. file; import java. io. IOException; /*** Oracle Database Backup *** @ author GaoHuanjie */public class OracleDatabaseBackup {/*** Java code for Oracle Database Export ** @ author GaoHuanjie * @ param userName required username * @ param password the password required to enter the database * @ param SID the SID of the user * @ param savePath Database Export File Storage path * @ param fileName Database Export File name *@ return true indicates that the export is successful, otherwise, false is returned. */Public static boolean exportDatabaseTool (String userName, String password, String SID, String savePath, String fileName) throws InterruptedException {File saveFile = new File (savePath); if (! SaveFile. exists () {// If the directory does not exist saveFile. mkdirs (); // create a folder} try {Process process = runtime.getruntime(cmd.exe c ("exp" + userName + "/" + password + "@" + SID + "file =" + savePath + "/ "+ fileName + ". dmp "); if (process. waitFor () = 0) {// 0 indicates that the thread is terminated normally. 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 ("the database is backed up successfully !!! ");} Else {System. out. println (" database backup failed !!! ");}}}
Q: How can I use java to back up Oracle databases?
Java. lang. Runtime
Processexec (String command)
Executes the specified string command in a separate process.
Call oracle's exp/imp command, command usage, Baidu, a lot
Use java code to back up and restore Oracle databases (stored as dmp or SQL)
Backup: Send SQL to mssqlserver:
Backup database <your database name> to disk = 'backup filename 'with init
Note: 1. the backup file name must be an absolute path,
2. the backup file can only be the path on the machine where mssqlserver is located. mssql supports backing up data to the network location.
Recovery:
Restore database <your database name> from disk = 'backup filename 'with replace
Note that when executing a restore database, the database to be restored must not have any client connection, including itself (the connection to initiate the restore database command ). Use restore to connect to the master database and then send the restore command.
Otherwise, it must fail.
How can I use jsp?
Sorry, you used this!
<%
Connect to the Connection object first!
You must first establish a connection with the database.
Then you can simply use a statement like this on the jsp page.
Try {
String SQL = "backup database xncsims to disk = 'd: \ xncback. dat '";
St = con. createStatement ();
Rs1_st.exe cuteQuery (SQL );
}
Catch (SQLException e) {System. out. println (e. toString ());}
Catch (Exception e) {System. out. println (e. toString ());}
%>
Rs1_st.exe cuteQuery (SQL );
Here, your SQL statement is sent to the database for execution.
There is another paper for your reference.
Www.cqvip.com/..117188