分享

java导入导出dmp文件

 melodyjian 2019-01-14
Java代码  收藏代码
  1. package com.broada.oracle.export;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.IOException;  
  5. import java.io.InputStreamReader;  
  6.   
  7. public class JavaOracle {  
  8.     public static void main(String[] args) {  
  9.         //expFile();  
  10.         impFile("COSS_R2_CHENXING_NSBD_0624");  
  11.     }  
  12.   
  13.     // 从oracle导出  
  14.     public static void expFile() {  
  15.         String[] cmds = new String[3];  
  16.         String commandBuf = "exp COSS_R2_CHENXING_NSBD_0605/coss@220 file=c://test.dmp log=c://test.log";  
  17.         cmds[0] = "cmd";  
  18.         cmds[1] = "/C";  
  19.         cmds[2] = commandBuf.toString();  
  20.         Process process = null;  
  21.         try {  
  22.             process = Runtime.getRuntime().exec(cmds);  
  23.         } catch (IOException e) {  
  24.             e.printStackTrace();  
  25.         }  
  26.         boolean shouldClose = false;  
  27.         try {  
  28.             InputStreamReader isr = new InputStreamReader(process.getErrorStream());  
  29.             BufferedReader br = new BufferedReader(isr);  
  30.             String line = null;  
  31.               
  32.             //打印出读取的oracle导出信息  
  33.             while ((line = br.readLine()) != null) {  
  34.                 System.out.println(line);  
  35.                 if (line.indexOf("????") != -1) {  
  36.                     shouldClose = true;  
  37.                     break;  
  38.                 }  
  39.             }  
  40.         } catch (IOException ioe) {  
  41.             shouldClose = true;  
  42.         }  
  43.         if (shouldClose)  
  44.             process.destroy();  
  45.         int exitVal;  
  46.         try {  
  47.             exitVal = process.waitFor();  
  48.             System.out.print(exitVal);  
  49.         } catch (InterruptedException e) {  
  50.             e.printStackTrace();  
  51.         }  
  52.     }  
  53.   
  54.     // 导入oracle  
  55.     public static void impFile(String user) {  
  56.         String[] cmds = new String[3];  
  57.         String commandBuf = "imp system/broada123@220 fromuser=COSS_R2_CHENXING_NSBD_0605 touser=" + user  
  58.                 + " file=c://test.dmp ignore=y";  
  59.         cmds[0] = "cmd";  
  60.         cmds[1] = "/C";  
  61.         cmds[2] = commandBuf.toString();  
  62.         Process process = null;  
  63.         try {  
  64.             process = Runtime.getRuntime().exec(cmds);  
  65.         } catch (IOException e) {  
  66.             e.printStackTrace();  
  67.         }  
  68.         boolean shouldClose = false;  
  69.         try {  
  70.             InputStreamReader isr = new InputStreamReader(process.getErrorStream());  
  71.             BufferedReader br = new BufferedReader(isr);  
  72.             String line = null;  
  73.             while ((line = br.readLine()) != null) {  
  74.                 System.out.println(line);  
  75.                 if (line.indexOf("????") != -1) {  
  76.                     shouldClose = true;  
  77.                     break;  
  78.                 }  
  79.             }  
  80.         } catch (IOException ioe) {  
  81.             shouldClose = true;  
  82.         }  
  83.         if (shouldClose)  
  84.             process.destroy();  
  85.         int exitVal;  
  86.         try {  
  87.             exitVal = process.waitFor();  
  88.             System.out.print(exitVal);  
  89.         } catch (InterruptedException e) {  
  90.             e.printStackTrace();  
  91.         }  
  92.     }  
  93. }  

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约