[英]Restoring a MySQL backup
I wrote the following code to restore MySQL backup , 我写了以下代码来还原MySQL备份,
public boolean restoreDB(String dbUserName, String dbPassword) {
try {
NewClassx n = new NewClassx();
n.myf(2);
String source = jTextField1.getText();
Process runtimeProcess;
Connection con = CPool.getConnection();
Statement stmt = con.createStatement();
ResultSet res = null;
res = stmt.executeQuery("select @@datadir");
String Mysqlpath = "";
while (res.next()) {
Mysqlpath = res.getString(1);
}
Mysqlpath = Mysqlpath.replace("data", "bin");
CPool.closeConnection(con);
CPool.closeStatement(stmt);
CPool.closeResultSet(res);
// String[] executeCmd = new String[]{Mysqlpath + "\\mysql", "--user=" + dbUserName, " -e", "source " + "\"" + source + "\""};
// String executeCmd = Mysqlpath + "\\mysql - u "+ dbUserName +" -e "+ "\"" + source + "\"";
//mysql - u admin -p admin accounts <
String[] executeCmd = new String[]{Mysqlpath + "\\mysql", " project_db ", " --user=" + dbUserName, " -e", " source "+ " \"" + source + "\""};
// System.out.println(executeCmd);
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
JOptionPane.showInternalMessageDialog(this, "Backup restored successfully");
return true;
} else {
JOptionPane.showInternalMessageDialog(this, "Backup was not restored");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
on calling the above function , my application freezes without restoring any backup. 在调用上述函数时,我的应用程序冻结,而未还原任何备份。
您没有在字符串中写密码,在用户名后添加“ -p password”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.