I have tried to export and import the data base in my java project.But the execute command doesnt work. Following is the code I've done.
public boolean exportDatabase(String fromServer, String FileName, String FilePath, int ExportOpions)
{
try {
Class.forName(Driver).newInstance();
}
catch (final InstantiationException e) {
NLogger.writeDebugLog(e);
}
catch (final IllegalAccessException e) {
NLogger.writeDebugLog(e);
}
catch (final java.lang.ClassNotFoundException e) {
NLogger.writeDebugLog(e);
}
try {
String dbName ="DBsample";
String dbUser = "root";
String dbPass ="root";
String executeCmd ="CD "+FilePath+" mysqldump -u "+dbUser+ "-p"+dbPass+" "+dbName+ ">" +FileName;
Process runtimeProcess =Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if(processComplete == 0){
System.out.println("Backup taken successfully");
}
else {
System.out.println("Could not take mysql backup");
}
return true;
}
catch (final Exception ex) {
NLogger.writeErrorLog("Database Connection Failed ", ex.toString());
NLogger.writeDebugLog(ex);
return false;
}
}
This shows an error as
"Cannot run program "CD": CreateProcess error=2, The system cannot find the file specified"
How can I solve this issue?