0

I'm developing a software with NetBeans and I'm using MySQL as my Database server. I' planning to use two buttons as, "Backup Database" and "Restore Database" to respective functions. How to accomplish these functions? And for both functions, it would be awesome if File Chooser window is used for the functions too. Thanks in advance! :)

Nimila Hiranya
  • 4,842
  • 10
  • 35
  • 52

1 Answers1

0

What about creating a dump and saving it? and then running it when you want to restore?

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

EDIT:

Well since you say you dont really know how to achieve this then ill be more specific.

mysqldumpl must be run from a commandline for this pls read this link:

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

your code should look something like this:

String yourCommand = "mysqldump -h localhost -u [user] -p[database password] -c --add-drop-table --add-locks --all --quick --lock-tables [name of the database] > sqldump.sql";
Runtime.getRuntime().exec(yourCommand);

After that you should have succefully saved a file with all the data of your database

the last part of the string "sqldump.sql" is the name of the file, you can set your own name with file chooser, and replace that name with the one from the user, google will help you with that.

Well first get that done Post your code when you have it running and then we can tackle the restoring of the DB

Andres L
  • 683
  • 9
  • 20