I want to backup a MYSQL table from remote server to my local server and I have to do this in my java application. I am trying to run the follwing query to do so:
C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump --opt --where='1 limit 10' -h a.b.c.d -u root -proot remoteDB remotetable|mysql -u root -pcanada localDB
Query runs absoulutely fine when i run it through commandline but when i run it through my java application it is not able to create any backup and strangely does not show any output also.Following is the code:
public static void main(String[] args) {
Process p;
String s="C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump --opt " +
"--where='1 limit 1' -h a.b.c.d -u root -proot remoteDB remoteTable|mysql -u root -pcanada " +
"localDB";
try {
p = Runtime.getRuntime().exec(s );
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
}
catch (InterruptedException e) {
System.out.println("fsff"+e);
e.printStackTrace();
} catch (IOException e) {
System.out.println("fsdaf"+e);
e.printStackTrace();
}
}
Please could anyone suggest why I am not run it through my java application.Thanks in advance :)