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

#1 richa.a91   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";

(--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   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • 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