Jump to content

mysqldump file creates an empty sql file

- - - - -

  • Please log in to reply
3 replies to this topic

#1
j.lai

j.lai

    Newbie

  • Members
  • PipPip
  • 21 posts
I'm trying to create a backup file of my MySQL database for my java project and the mysqldump is creating an empty sql file. When I type the command in cmd.exe, it works fine.

Here is my java method:

public void backup(String location)
{
    Date date = new Date();
    String DATE_FORMAT="MMM-dd-yyyy";

    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    String fileName = sdf.format(date);
    String fileLocation = location+fileName+".sql";
    try
    {
        Runtime.getRuntime().exec("cmd /c C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump -u root -ppassword iliassembly > "
            +fileLocation);

    }
    catch (IOException e)
    {
        System.out.println(e.getMessage());
    }
}
Any help is appreciated. Thanks!

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
I don't much about this but I googled around and came across the following link several times throughout several other forums.
When Runtime.exec() won't - JavaWorld

*In short, you may not be seeing some hidden output when you execute this command.
Be sure to check out that first link.

Another user on this forum has a similar problem.
MYSQLDUMP from Java - Java Forums

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
C:\Program Files is protected under Vista and Windows 7. Try running your app as administrator and see if the problem persists.

#4
j.lai

j.lai

    Newbie

  • Members
  • PipPip
  • 21 posts
I was just speaking with my instructor and he suggested creating a batch file, and making the program execute the batch file. Any suggestions to that method?

EDIT:
So I tried running that command in the batch file but it still didn't work so I tried running that on a windows xp machine and it still didn't work

I got it working in the end in the batch file by first changing the directory to MySQL
then running MySQL.

It also works when I issue double quotes for the filepath so
Runtime.getRuntime().exec("Cmd /c \"C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump\" -u root -ppassword iliassembly > "
            +fileLocation);

Anyways, I appreciate all your help. thanks guys!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users