wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes try to run sql script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "try to run sql script" Watch "try to run sql script" New topic

try to run sql script

Pranoj Ashtamkar

Joined: Mar 25, 2008
Posts: 7
public class RealTimeMap2 {
public static void main(String argv[]) {
try {
System.out.println("going to process");

String username = "root";
String password = "root";
String database = "test_db";

//Successfully executed
String[] executeCmd = new String[]{"mysql","test_db","--user=root","--password=root","-e"," source d:/test_query.sql" };


// but if i want to pass this way with user varible its not process that file, nor throwing any runtime exception
//String executeCmd = "mysql "+database+" --user="+username+" --password="+password+" -e source d:/test_query.sql";

System.out.println("---> cmd : "+executeCmd);

//Runtime.getRuntime().exec(new String[]{"mysql",database,"--user="+username,"--password="+password,"-e"," source d:/test_query.sql"});

System.out.println("---> done");

} catch (Exception err) {
System.out.println("---> error: "+err);


any body help please.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46356
Please use the code button.

This may not be an SQL problem, but a problem with Runtime.exec(). You must empty the two streams associated with the Runtime, and you must wait until the process has completed before trying anything else. Look at the ProcessBuilder class, which can make things slightly easier by combining the two streams, but you really must read Michael Daconta's classic article "When Runtime.exec() won't" before going anywhere near Runtime.
I agree. Here's the link: http://aspose.com/file-tools
subject: try to run sql script
It's not a secret anymore!