We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Mysql database back up from java application

In my desktop application whenever execute the code to backup my database from java application the app goes on waiting state may be for password , which we have to enter while backing up from command line. But i've provided the username and password of database in the code. Why is it going on waiting state. please help how can i do this. My execution code is:

  public boolean backupDB(String dbName, String dbUserName, String dbPassword) {

        Process runtimeProcess;
        try {

       runtimeProcess = Runtime.getRuntime().exec("C://xampp//mysql//bin//mysqldump -u"+ dbUserName+" -p "+dbPassword+" dbName+" > D://backup.sql");

            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;
    }
2
Contributors
1
Reply
1 Day
Discussion Span
9 Months Ago
Last Updated
3
Views
47pirates
Junior Poster
129 posts since Dec 2009
Reputation Points: 19
Solved Threads: 1
Skill Endorsements: 0

Try the following code:

import java.util.*;
import java.io.*;
public class BackUpSql {
    public static void main(String[] args) {
        try {
            Runtime rt = Runtime.getRuntime();
            rt.exec("cmd.exe /c start C:\\ab.bat");
            System.exit(0);
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

Here is the ab.bat:

set path=%path%;C:\Program files\MySQL\MySQL Server 5.0\bin;
mysqldump -uroot -proot register > C:\back.sql

where root is the username and password and register is the database.
You have to set the path to bin folder of mysql in the first line of ab.bat correctly.

rajesh1158
Junior Poster in Training
59 posts since Oct 2010
Reputation Points: 4
Solved Threads: 1
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0567 seconds using 2.67MB