我想备份我的远程mysql数据库。我看过很多例子,但我找不到答案我做错了。我的计算机上有mysql服务器,其名称不是我的远程数据库,只是想在我的计算机上创建一个sql文件来复制。 我的按钮动作执行代码是:
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();
}
答案 0 :(得分:0)
系统找不到指定的文件
尝试添加文件路径
executeCmd = "/usr/bin/mysqldump -hwww.db4free.net -u DBUSER -pDBPASSWORD DBNAME > backup.sql";