I want to create dump file of sqlite database from java but I can't run the below command from linux. I got the help of windows and I tried with linux but it appears one terminal nothing more than that. So can anyone help me how to write this command in linux?

  Process p = Runtime.getRuntime().exec("cmd /c start /b sqlite3 db.sqlite .dump > dump.txt");

My implementation in Linux is below:

String command= "/usr/bin/xterm"; 
Runtime rt = Runtime.getRuntime();  
Process p = rt.exec(new String[]{command , "/home/ubuntu/test.sqlite .dump > /home/ubuntu/newsql111.sql"});

Can anyone tell me where is my mistake?


You don't need an xterm but you do need a sqlite3. That is you are running

/usr/bin/xterm /home/ubuntu/test.sqlite .dump > …

when you really need to run

/bin/sh -c "sqlite3 /home/ubuntu/test.sqlite .dump > …"

where I am assuming your database is …/test.sqlite. I'll leave the Java specifics to you.

| improve this answer | |
  • when i running this code it gives me error.. java.io.IOException: Cannot run program "/bin/sh -c ": error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) at java.lang.Runtime.exec(Runtime.java:615) at java.lang.Runtime.exec(Runtime.java:483) at sqlitedbtest.Test.main(Test.java:22) Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) – Java D Oct 22 '13 at 6:47
  • @msw.. hey when i run this command it works but when i am trying to dump in the folder where space in between name.. at that time does not work? – Java D Dec 14 '13 at 10:29

I found the solution:

 Process p = rt.exec(new String[]{"/bin/sh", "-c", "sqlite3 /home/ubuntu/testingdb.sqlite .dump > /home/ubuntu/success11.sql"});

It gives full dump file of sqlite database..

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.