Results 1 to 5 of 5
  1. #1
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default [SOLVED]Auto backup of MySQL in JAVA

    I am tring to write a code which will create a backup of mysql.
    HEre is the sample code I have done.but its not working.
    Java Code:
     try{
         Runtime.getRuntime().exec("C://Program Files/MySQL/MySQL Server 5.0/bin/mysqldump -hlocalhost -uroot -p ABC --result-file=E:\\COMP.sql");
            }catch(Exception e){
                e.printStackTrace();
            }
    Last edited by UJJAL DHAR; 04-30-2012 at 08:35 PM.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Auto backup of MySQL in JAVA

    When Runtime.exec() won't

    Be sure to read all sections and implement all recommendations.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Auto backup of MySQL in JAVA

    Thanks a lot.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  4. #4
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Auto backup of MySQL in JAVA

    I have solved that problem.Now a new problem arises.

    Java Code:
      String sql = "" ;
            try {
    
                String dump = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump " //Path to mysql
                        + "--host=localhost " //Mysql hostname
                        + "--port=3306 " //Mysql portnumber
                        + "--user=root " //Mysql username
                        + "--password= " //Mysql password
                        + "--add-drop-table " //Add a DROP TABLE statement before each CREATE TABLE statement
                        + "--add-drop-database " //Add a DROP DATABASE statement before each CREATE DATABASE statement
                        + "--complete-insert " //Use complete INSERT statements that include column names.
                        + "--extended-insert " //Use multiple-row INSERT syntax that include several VALUES lists
                        + "from_st_school";                  //Mysql databasename
    
                Process run = Runtime.getRuntime().exec(dump);
    
                InputStream in = run.getInputStream();
                InputStreamReader isr = new InputStreamReader(in);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
    
                //System.out.println("<ERROR>");
               // int i=0;
                while ((line = br.readLine()) != null) {
                    System.out.println(line);
                    sql += line;
                }
    
                int exitVal = run.waitFor();
                //   System.out.println("Process exitValue: " + exitVal);
                BufferedWriter out;
                try {
                    out = new BufferedWriter(new FileWriter("from_st_school.sql"));
                    out.write(sql);
                  
                    out.close();
                } catch (IOException ex) {
                }
    
    
            } catch (Throwable t) {
                t.printStackTrace();
            }
    It displays line by line in the output screen.But I am tring to append all in sql to write into a file. But error occurs.

    Java Code:
    java.lang.OutOfMemoryError: Java heap space
    Help please.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Auto backup of MySQL in JAVA

    Write each line to the file as you read it. Don't forget to flush()/close() the writer/output stream.

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with BACKUP and RESTORE MYSQL DATABASE
    By timoxa in forum New To Java
    Replies: 4
    Last Post: 03-24-2012, 05:33 AM
  2. Oracle backup with Java
    By WeaponX in forum Advanced Java
    Replies: 4
    Last Post: 07-03-2011, 01:18 AM
  3. Replies: 12
    Last Post: 04-18-2009, 12:58 AM
  4. MySQL + Java - auto incrementation issue
    By int80 in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 06:04 PM
  5. MySQL 5.0 data backup from java
    By sanjay_sharma77 in forum JDBC
    Replies: 1
    Last Post: 11-06-2007, 12:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •