我想對遠程mysql數據庫進行備份。我查看了很多例子,但我無法找到答案,我做錯了什麼。我的計算機上有我的遠程數據庫以外的其他名稱的mysql服務器,只是想在我的計算機上創建sql文件以獲得副本。 我的按鈕操作執行的代碼是:從遠程數據庫備份mysql與mysqldump進程錯誤
try {
String cs = "jdbc:mysql://db4free.net:3306/DBNAME?user=DBUSER&password=DBPASSWORD";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = java.sql.DriverManager.getConnection(cs);
String executeCmd = "";
if (connection != null) {
executeCmd = "mysqldump -hwww.db4free.net -u DBUSER -pDBPASSWORD DBNAME > backup.sql";
Process runtimeProcess = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", executeCmd });
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
JOptionPane.showMessageDialog(rootPane, "OK");
} else {
JOptionPane.showMessageDialog(rootPane, "Didn't make a copy.");
}
} else {
JOptionPane.showMessageDialog(rootPane, "Failed");
}
} catch (Exception e) {
e.printStackTrace();
}
重複的http://stackoverflow.com/questions/13376132/backup-mysql-database -java-code –