Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Restore

public static void Restoredbfromsql(String s) {
        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 = YourImplementingClass.class.getProtectionDomain().getCodeSource();
            File jarFile = new File(codeSource.getLocation().toURI().getPath());
            String jarDir = jarFile.getParentFile().getPath();

            /*NOTE: Creating Database Constraints*/
             String dbName = "YourDBName";
             String dbUser = "YourUserName";
             String dbPass = "YourUserPassword";

            /*NOTE: Creating Path Constraints for restoring*/
            String restorePath = jarDir + "ackup" + "" + s;

            /*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, "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());
        }

    }
Comment

PREVIOUS NEXT
Code Example
Java :: Marging ViewPager 
Java :: android adb is using too much cpu 
Java :: how to make a messages config minecraft plugin 
Java :: worldedit api copy schematic 
Java :: search in row and column sorted matrix leetcode 
Java :: list in list 
Java :: full screen in libgdx Lwjgl3 
Java :: Remove ArrayList Elements using remove() function 
Java :: trier un tableau de string java 
Java :: android stop audio playing by activity lifecycle 
Java :: java resultset to object 
Java :: how to select a audio from android programmaticly 
Java :: Get Subarray from Array 
Java :: SmallChange 
Java :: what does .set do in java 
Java :: pattern exercises for java 
Java :: do i have to import files from the same package in java 
Java :: java catch stop signal 
Java :: android frame to bitmap is null 
Java :: Creating strings using the new keyword Java 
Java :: dialog background dimming in android 
Java :: Period java springboot 
Java :: x squared unicode java code 
Java :: convert jython object to java object 
Java :: return vs break 
Java :: java overloading 
Java :: licenceurl 
Java :: number output swing java 
Java :: java bean go to other page 
Java :: retrofit gradle 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =