1

So I am still learning programming, I am creating a simple application that can backup a database but the problem is when I click the button for backup, nothing happens, it does not even display the "can't create backup". I am using xampp, in case that is relevant. I have zero idea as to why is it is not working, and I am really curios what is the reason behind it, any help will be greatly appreciated.

...
String path = null;
String filename;

//choose where to backup

 private void jButtonLocationActionPerformed(java.awt.event.ActionEvent evt)   {                                         
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(this);
    String date = new SimpleDateFormat("MM-dd-yyy").format(new Date());

    try {
        File f = fc.getSelectedFile();
        path = f.getAbsolutePath();
        path = path.replace('\\', '/');
        path = path+"_"+date+".sql";
        jTextField1.setText(path);

    } catch (Exception e) {
        e.printStackTrace();
    }
} 

//backup
private void jButtonBackUpActionPerformed(java.awt.event.ActionEvent evt) {                                         
    Process p = null;


    try{
        Runtime runtime = Runtime.getRuntime();

        p=runtime.exec("C:/xampp/mysq/bin/mysqldump -u root --add-drop-database -B capstone -r "+path);

        int processComplete = p.waitFor();
        if (processComplete==0) {
            jLabel1.setText("Backup Created Success!");
        } else {
            jLabel1.setText("Can't create backup.");
        }
    } catch (Exception e) {

    }


} 
1
  • It looks like your actions aren't bound to anything... Commented Dec 7, 2017 at 16:44

3 Answers 3

0

You use a try-catch block in the jButtonBackUpActionPerformed, but the catch statement is empty. Therefore, if an exception is raised for whatever reason, no file would be written and you would get no output. You can try to use e.printStackTrace() like in the catch statement of the other button for debugging.

Sign up to request clarification or add additional context in comments.

Comments

0

I found the underlying problem, thanks to stan. It was a typo problem, instead of "mysql", I have put "mysq" thank you guys!

  java.io.IOException: Cannot run program "C:/xampp/mysq/bin/mysqldump.exe": CreateProcess error=2, The system cannot find the file specified

Comments

0

this will run any shell script on Linux server. Test it on windows ... shoud work too

 public static int executeExternalScript(String path) throws InterruptedException, IOException {

  ProcessBuilder procBuilder = new ProcessBuilder(path); 
  procBuilder.redirectErrorStream(true);
  Process process = procBuilder.start();
  BufferedReader brStdout = new BufferedReader(new InputStreamReader(process.getInputStream()));

  String line = null;
  while((line = brStdout.readLine()) != null) {   logger.info(line);   }
      int exitVal = process.waitFor();
      brStdout.close();
      return exitVal;}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.