wood burning stoves 2.0*
The moose likes JDBC 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
Bookmark "try to run sql script" Watch "try to run sql script" New topic
Author

try to run sql script

Pranoj Ashtamkar
Greenhorn

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" };

Runtime.getRuntime().exec(executeCmd);

// 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
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
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
 
Similar Threads
Java-Xml file not getting Connected to DataBase
com.sun.net.ssl.internal.ssl.Provider()
Can't Delete File with Process
JSP problem in code
Help with this code!