0

Goodmorning everyone. I have a problem with my java program: i would like to create a directory to store a .sql file, which will be generated through mysqldump.exe. I've been trying to follow guides on Stack Overflow or others, but i still can't resolve my problem: directory and .sql file are generated, but the file is totally blank. The best part is that pasting the same command (ctrl+C, ctrl+V) on the command line, it works well and generates an ordinary .sql file for a dump operation.

Please help me. I'm using NetBeans 8.0.2 as IDE, there's my code (there are some variables, like SelectedTable, that allows me to get the current user, password etc. Don't care about them: those parts works and the command is correctly generated):

 private void jMenuExternalBackupActionPerformed(java.awt.event.ActionEvent evt) { 
 LocalDate today = LocalDate.now();
 GregorianCalendar now = new GregorianCalendar();
 String BackupFolderName = SelectedTable.getMaster().getName()+" "+SelectedTable.getName()+" "+today.getYear()+"_"+today.getMonth().getValue()+"_"+today.getDayOfMonth()+" "+now.get(now.HOUR_OF_DAY)+"_"+now.get(now.MINUTE)+"_"+now.get(now.SECOND);
 new File("/HyperSQL/Backups/").mkdirs();
 new File("/HyperSQL/Backups/"+BackupFolderName+"/").mkdirs();
 String command; 
 if (SelectedTable.getMasterApplication().getPassword().isEmpty())
 command = "mysqldump -u" + SelectedTable.getMasterApplication().getUserLogged() + " " + SelectedTable.getMaster().getName() + ""
 + " > \"C:\\HyperSQL\\Backups\\"+BackupFolderName+"\\backup.sql\"";
 else
 command = "mysqldump -u" + SelectedTable.getMasterApplication().getUserLogged() + " -p" + SelectedTable.getMasterApplication().getPassword() + " " + SelectedTable.getMaster().getName() + ""
 + " > \"C:\\HyperSQL\\Backups\\"+BackupFolderName+"\\backup.sql\""; 
 try
 {
 Process exec = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c", command});
 }
 catch (Exception e)
 {
 e.printStackTrace();
 }
} 
asked Feb 13, 2016 at 14:06
7
  • Possible duplicate of stackoverflow.com/questions/5969724/… Commented Feb 13, 2016 at 14:11
  • Is the "mysqldump" program on the command search path? Try using the full pathname for mysqldump instead. Commented Feb 13, 2016 at 14:31
  • hmm, you might want to print out the content of the output stream and error stream to make sure there is no error. Commented Feb 13, 2016 at 15:41
  • @StephenC i tried to but it doesn't create the file... Commented Feb 13, 2016 at 23:59
  • Have you tried looking at the error message (stderr) and the exit status? Commented Feb 14, 2016 at 0:09

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.