Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void BackupDBtosql(String Failname) {
- try {
- /*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 folder saving*/
- /*NOTE: Here the backup folder is created for saving inside it*/
- String folderPath = jarDir + "\\backup";
- /*NOTE: Creating Folder if it does not exist*/
- File f1 = new File(folderPath);
- f1.mkdir();
- /*NOTE: Creating Path Constraints for backup saving*/
- /*NOTE: Here the backup is saved in a folder called backup with the name backup.sql*/
- // String savePath = "\"" + jarDir + "\\backup\\" + ?"mustafa.sql\"?";
- String savePath = Failname + ".sql";
- /*NOTE: Used to create a cmd command*/
- String executeCmd = "mysqldump -u" + dbUser + " -p" + dbPass + " --database " + dbName + " -r " + savePath;
- /*NOTE: Executing the command here*/
- 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 ex) {
- JOptionPane.showMessageDialog(null, "Error at Backuprestore" + ex.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement