0
的東西與我的數據庫恢復計劃會錯,這個錯誤隱藏我的幸福:產生java.io.IOException:不能運行程序「的MySQL」:CreateProcess的錯誤= 2,系統找不到指定的文件
產生java.io.IOException:不能運行程序「的MySQL」:CreateProcess的錯誤= 2, 該系統找不到指定的文件
文件要恢復位於d:當我/Backup/backup.sql瀏覽並從此路徑打開文件,然後單擊恢復按鈕時出現錯誤。請幫我解決這個問題。下面是 是我的代碼JFileChooser
用於瀏覽文件位置。
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);
}
}
}
);