I tried to run the following code, which should back up my database , but it shows some runtime errors.
But I tried to run the System.out.println () output part (which I commented on in this code) in the mysql shell, and it worked >.
It displays a problem with the io file. Plz someone helps me.
package files; public class tableBackup_1 { public boolean tbBackup(String dbName,String dbUserName, String dbPassword, String path) { String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " --add-drop-database -B " + dbName + " -r " + path; Process runtimeProcess; try { System.out.println(executeCmd);//this out put works in mysql shell runtimeProcess = Runtime.getRuntime().exec(executeCmd); int processComplete = runtimeProcess.waitFor(); if (processComplete == 0) { System.out.println("Backup created successfully"); return true; } else { System.out.println("Could not create the backup"); } } catch (Exception ex) { ex.printStackTrace(); } return false; } public static void main(String[] args){ tableBackup_1 bb = new tableBackup_1(); bb.tbBackup("test","harin","1234","C:/Users/Master/Downloads/123.sql"); } }
mysqldump -u harin -p1234
source share