如何用JAVA调用本地EXP命令备份数据库?

[复制链接]
查看11 | 回复7 | 2007-9-26 17:05:15 | 显示全部楼层 |阅读模式
菜鸟求助:如何用JAVA调用本地EXP命令备份数据库?
用下面这个办法不行啊
String cmd = "";

cmd ="cmd /c c:\\Oracle\\BIN\\exp.exe system/manager buffer=40960000 file=aa.dmp log=aa.log";

try {

Process p =Runtime.getRuntime().exec("cmd&quot

;
}
catch (IOException ex) {}
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
看看我的blog里边,有这样一片文章
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
谢谢楼上的兄弟,我先去看看你的BLOG:)
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
我看了你的那篇java.lang.Runtime.exec笔记,还是不知道该怎么办啊 我很菜的:(谁能给我讲讲该怎么用JAVA实现EXP呢??
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
里边说道的很清楚啊,你也可以看看原来的E文
恩,你的现象里边有提及,应该是exec无法象shell一样的运行,你的参数无法传递给你的命令
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
关注一下……
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层

Process p =Runtime.getRuntime().exec(cmd);
不是
Process p =Runtime.getRuntime().exec("cmd&quot

;
回复

使用道具 举报

千问 | 2007-9-26 17:05:15 | 显示全部楼层
在老外的网站上找到一个类可以实现:
import java.io.*;
/**
*Description of the Class
*
* @author Administrator
* @created23 February 2004
*/
public class RunAsync {
/**
*Description of the Method
*
* @paramargsDescription of the Parameter
*/
public static void main(String args[]) {

try {

if (args.length &quot

;

System.exit(-1);

}

Process pro = null;

if (args.length > 1) {

pro = Runtime.getRuntime().exec(args);

}

else {

pro = Runtime.getRuntime().exec(args[0]);

}

InputStream error = pro.getErrorStream();

InputStream output = pro.getInputStream();

Thread err = new Thread(new OutErrReader(error));

Thread out = new Thread(new OutErrReader(output));

out.start();

err.start();

pro.waitFor();

}

catch (java.io.IOException e) {

e.printStackTrace();

}

catch (java.lang.InterruptedException e) {

e.printStackTrace();

}
}

/**
*Description of the Class
*
* @author Administrator
* @created23 February 2004
*/
static class OutErrReader implements Runnable {

InputStream is;


/**
*Constructor for the OutErrReader object
*
* @paramisDescription of the Parameter
*/

public OutErrReader(InputStream is) {

this.is = is;

}


/**
*Main processing method for the OutErrReader object
*/

public void run() {

try {

BufferedReader in = new BufferedReader(new InputStreamReader(is));

String temp = null;

while ((temp = in.readLine()) != null) {

// System.out.println(temp);

Frame1.jTextArea1.append("\n&quot

;

Frame1.jTextArea1.append(temp);

}

is.close();

}

catch (Exception e) {

e.printStackTrace();

}

}
}
}
我稍加修改了一下:
package oraclem;
import java.io.*;
public class RunCmd{
public static void run(String s){
try{Process pro=Runtime.getRuntime().exec(s);
InputStream error=pro.getErrorStream();
InputStream output = pro.getInputStream();
NewThread err=new NewThread(error);
NewThread out=new NewThread(output);
err.start();
out.start();
pro.waitFor();
}catch (java.io.IOException e) {

e.printStackTrace();

}

catch (java.lang.InterruptedException e) {

e.printStackTrace();

}
}

}

class NewThread extends Thread{
InputStream is;
public NewThread(InputStream is){
this.is=is;}
public void run(){
try{BufferedReader in = new BufferedReader(new InputStreamReader(is));
String temp = null;
while ((temp = in.readLine()) != null) {
// System.out.println(temp);
Frame1.jTextArea1.append("\n&quot

;
Frame1.jTextArea1.append(temp);
}
}catch (Exception e) {

e.printStackTrace();}
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行