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! :)
我正在使用NetBeans开发一个软件,我使用MySQL作为我的数据库服务器。我计划将两个按钮用作“备份数据库”和“恢复数据库”到各自的功能。如何完成这些功能?对于这两个函数,如果File Chooser窗口也用于函数,那将是非常棒的。提前致谢! :)
1 个解决方案
#1
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:
必须从命令行运行mysqldumpl才能阅读此链接:
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.
字符串“sqldump.sql”的最后一部分是文件的名称,您可以使用文件选择器设置自己的名称,并将该名称替换为用户的名称,谷歌将帮助您。
Well first get that done Post your code when you have it running and then we can tackle the restoring of the DB
首先完成这项工作在运行代码后发布代码然后我们可以解决数据库的恢复问题
#1
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:
必须从命令行运行mysqldumpl才能阅读此链接:
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.
字符串“sqldump.sql”的最后一部分是文件的名称,您可以使用文件选择器设置自己的名称,并将该名称替换为用户的名称,谷歌将帮助您。
Well first get that done Post your code when you have it running and then we can tackle the restoring of the DB
首先完成这项工作在运行代码后发布代码然后我们可以解决数据库的恢复问题