Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Restoredbfromsql() {
- try {
- /*NOTE: String s is the mysql file name including the .sql in its name*/
- /*NOTE: Getting path to the Jar file being executed*/
- /*NOTE: YourImplementingClass-> replace with the class executing the code*/
- CodeSource codeSource = ?Main_Screen?.class.getProtectionDomain().getCodeSource();
- File jarFile = new File(codeSource.getLocation().toURI().getPath());
- String jarDir = "E:\\";
- /*NOTE: Creating Database Constraints*/
- String dbName = ?"electrical"?;
- String dbUser = ?"root"?;
- String dbPass = ?"root"?;
- /*NOTE: Creating Path Constraints for restoring*/
- JFileChooser jfc = new JFileChooser();
- jfc.showOpenDialog(null);
- File f = jfc.getSelectedFile();
- // String restorePath = jarDir + "\\backup" + "\\" + s;
- String restorePath = jfc.getSelectedFile().getAbsolutePath();
- /*NOTE: Used to create a cmd command*/
- /*NOTE: Do not create a single large string, this will cause buffer locking, use string array*/
- String[] executeCmd = new String[]{"mysql", dbName, "-u" + dbUser, "-p" + dbPass, "-e", " source " + restorePath};
- /*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
- Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
- int processComplete = runtimeProcess.waitFor();
- /*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
- if (processComplete == 0) {
- JOptionPane.showMessageDialog(null, "تم استعادة معلوماتك بنجاح");
- } else {
- JOptionPane.showMessageDialog(null, "لم يتم استعادة المعلومات");
- }
- } catch (URISyntaxException | IOException | InterruptedException | HeadlessException ex) {
- JOptionPane.showMessageDialog(null, "Error at Restoredbfromsql" + ex.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement