Guest User

Untitled

a guest
May 4th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*NOTE: Creating Database Constraints*/
  2. String dbName = "biblioteca2";
  3. String dbUser = "root";
  4. String dbPass = "";
  5.  
  6. /*NOTE: Creating Path Constraints for restoring*/
  7. String restorePath = jarDir + "\backup" + "\" + s;
  8.  
  9. /*NOTE: Used to create a cmd command*/
  10. /*NOTE: Do not create a single large string, this will cause buffer locking, use string array*/
  11. String[] executeCmd = new String[]{"mysql", dbName, "-u" + dbUser, "-p" + dbPass, "-e", " source " + restorePath};
  12.  
  13. /*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
  14. Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
  15. int processComplete = runtimeProcess.waitFor();
  16.  
  17. /*NOTE: processComplete=0 if correctly executed, will contain other values if not*/
  18. if (processComplete == 0) {
  19. JOptionPane.showMessageDialog(null, "Successfully restored from SQL : " + s);
  20. } else {
  21. JOptionPane.showMessageDialog(null, "Error at restoring");
  22. }
  23.  
  24.  
  25. } catch (Exception ex) {
  26. JOptionPane.showMessageDialog(null, "Error at Restoredbfromsql" + ex.getMessage());
  27. }
  28.  
  29. }
Add Comment
Please, Sign In to add comment