Something is going wrong with my program for database recovery, this error hides my happiness:
java.io.IOException: Cannot run program "mysql":CreateProcess error=2, The system cannot find the file specified
file to be recovered is located in D:/Backup/backup.sql when I browse and open the file from this path then error appears when I click recovery button. Please help me solve this problem.
below is my code with JFileChooser for browsing file location.
browseButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
String recPath = "";
JFileChooser fc = null;
if (fc == null) {
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setAcceptAllFileFilterUsed(false);
}
int returnVal = fc.showDialog(null, "Open");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
recPath = file.getAbsolutePath();
sourceField.setText(recPath);
}
}
}
);
recoveryButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
try{
String databaseName ="jdbc:mysql://localhost:3306/myDB";
String userName ="abc";
String password ="123";
String source = sourceField.getText();
int processComplete;
String[] executeCmd = new String[]{"mysql",databaseName, "--user=" + userName, "--password=" + password, "-e", "source"+source};
//sava the command in a array
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);// execute the command
processComplete = runtimeProcess.waitFor();// get the result to variable
if(processComplete==1){
JOptionPane.showMessageDialog(null, "Restore Failed");
}
else if(processComplete==0){
JOptionPane.showMessageDialog(null, "Restore Completed");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(null,ex);
}
}
}
);