Back up and restore Oracle databases in Java

Source: Internet
Author: User

Back up and restore the Oracle database in Java. I don't know if there are any better methods. I hope some of them can also provide the following methods or code.

Package com. servlet. util;

Import java. io. File;
Import java. io. FileOutputStream;
Import java. io. IOException;
Import java. io. InputStream;
Import java. nio. ByteBuffer;
Import java. nio. channels. Channels;
Import java. nio. channels. FileChannel;
Import java. nio. channels. ReadableByteChannel;
Import java. util. ArrayList;
Import java. util. List;
Import java. util. Map;

/**
* Database backup and Restoration
* @ Author RootSuper
* @ Version 2012-11-12
*/
@ SuppressWarnings ("unused ")
Public class BackupOracleDatabase {

/** User name */
Private String userName;
/** Password */
Private String userPass;
/** Service address */
Private String serverAddr;
/** Backup file path */
Private String backupFilePath;
/** Backup log path */
Private String logPath;

/**
* Constructor
* @ Param userName: database userName
* @ Param userPass Database User Password
* @ Param serverAddr service address: Port/Database Name
* @ Param backupFilePath: backup file path
*/
Public BackupOracleDatabase (String Name, String Pass,
String Addr, String FilePath, String log ){
This. userName = Name;
This. userPass = Pass;
This. serverAddr = Addr;
This. backupFilePath = FilePath;
This. logPath = log;
}

 
/**
* Get the command string
* @ Param bool whether the command string for restoring the database is the BACKUP command by default
* @ Return commStr command string
*/
Private String GetCommand (boolean bool ){
String commStr = "EXP @ USER @/@ PASSWORD @ SERVER @ FILE = @ FILEPATH @ LOG = @ LOGPATH @ FULL = Y ";
If (bool ){
CommStr = "IMP @ USER @/@ PASSWORD @ SERVER @ FILE = @ FILEPATH @ LOG = @ LOGPATH @ FULL = Y ";
}
String temp = commStr. replaceAll ("@ USER @", this. userName ). replaceAll ("@ PASSWORD @", this. userPass ). replaceAll ("@ SERVER @", this. serverAddr ). replaceAll ("@ FILEPATH @", this. backupFilePath ). replaceAll ("@ LOGPATH @", this. logPath );
System. out. println (temp );
Return temp;
}
 

/**
* Back up or restore a database
* @ Param bool: Restore database false: Back up database
* @ Return boolean
*/
Public boolean expBackup (boolean bool ){
Runtime rt = Runtime. getRuntime ();
Process processexp = null;
Try {
Processexp = rt.exe c (GetCommand (bool ));
Return true;
} Catch (IOException e ){
E. printStackTrace ();
}
Return false;
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.