My Requirement is, I have one Oracle database server(Linux) and one File Server(Linux). Using Java, I have to connect to the File server and take a copy of exp dump from the database server.
Below is the piece of code written to accomplish the same but getting the error "bash: exp: command not found". Someone help me to execute exp command using Java. Thanks for all your efforts and help.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public static boolean exportDataBase ()
{
String exportCommand = " exp UserName/Password@DB_SID file=DB_METADATA.dmp ROWS=n statistics=none log=DB_METADATA_exp.log Owner=USER1 ";
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session = jsch.getSession(ftpUserName, ftpServer, 22);
session.setPassword(ftpPassword);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(exportCommand);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
System.out.println("exit-status: " + channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
System.out.println("DONE");
} catch (Exception e) {
e.printStackTrace();
}
}