1 Replies - 373 Views - Last Post: 28 December 2012 - 06:14 AM Rate Topic: -----

#1 richa.a91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-December 12

Running mysqldump from java in linux

Posted 28 December 2012 - 04:30 AM

--The following command works fine when run directly on terminal

mysqldump -uabc -pabc1234 --compact --no-create-info -w \"fieldname != 'A'\" dbname tablename -hhostaddress --result-file=/tmp/myfile.txt


--But when it is executed using Runtime() method then it does not produce the output in the destination file.

String s="mysqldump -uabc -pabc1234 --compact --no-create-info -w \"fieldname != 'A'\" dbname tablename -hhostaddress --result-file=/tmp/myfile.txt";
Runtime.getRuntime().exec(s);


(--say abc is the username and abc1234 the password)

The same problem occurs if redirection to the destination file ( > ) is usedinstead of --result-file option.
What shall i do to execute it from within a java program ?

Is This A Good Question/Topic? 0
  • +

Replies To: Running mysqldump from java in linux

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,996
  • Joined: 20-September 08

Re: Running mysqldump from java in linux

Posted 28 December 2012 - 06:14 AM

Have a look at http://technojeeves..../52-runtimeexec

The more complex the command, the more likely you are to get better results using the String[] form of Runtime.exec. I would also be consistent with the parameter formats, using the longer style as more readable. One of your trickier ones would be something like

command[5] = "--where=\"fieldname != 'A'\"";
An easier way would be to place the command that works into a script and Runtime.exec that script

This post has been edited by g00se: 28 December 2012 - 01:26 PM
Reason for edit:: Easier

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1