Home  >  Article  >  Database  >  Java代码实现向Oracle数据库中导入已备份的数据库文件

Java代码实现向Oracle数据库中导入已备份的数据库文件

WBOY
WBOYOriginal
2016-06-07 16:43:42835browse

今天将很早就实现的一个Oracle数据库备份功能粘贴出来,这个功能是在大学做阶段设计时写的:

今天将很早就实现的一个Oracle数据库备份功能粘贴出来,这个功能是在大学做阶段设计时写的:

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 不包含扩展名的数据库备份文件路径
  * @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

本文永久更新链接地址:

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn