public static void Restoredbfromsql(String s) {
try {
CodeSource codeSource = YourImplementingClass.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
String dbName = "YourDBName";
String dbUser = "YourUserName";
String dbPass = "YourUserPassword";
String restorePath = jarDir + "\\backup" + "\\" + s;
String[] executeCmd = new String[]{"mysql", dbName, "-u" + dbUser, "-p" + dbPass, "-e", " source " + restorePath};
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
JOptionPane.showMessageDialog(null, "Successfully restored from SQL : " + s);
} else {
JOptionPane.showMessageDialog(null, "Error at restoring");
}
} catch (URISyntaxException | IOException | InterruptedException | HeadlessException ex) {
JOptionPane.showMessageDialog(null, "Error at Restoredbfromsql" + ex.getMessage());
}
}