This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have to execute mysql command line syntax from java runtime, that should work in both windows and linux machine. I tried using the Runtime.getRuntime().exec("cmd /c mysql -u username -p pass databasename < c:backup.sql");
But this is not restoring my database, instead im getting the mysql version and options information in the console trace.
Trying something at the command line is not a good enough test. The command line is a shell which takes care of redirects (where you put < filename to take the input from a file). But Runtime.exec() does not start a shell, it just attempts to run an executable with parameters.
So, if you want your input to come from a file, you will have to provide that input by passing it to the Process's InputStream. Or OutputStream, whichever it is, you could look it up in the documentation.
Or you could use a .bat file as already suggested. Nobody has yet linked to the article When Runtime.exec() won't which you should really read.