通过我的java代码导出数据库 [英] Exporting database through my java code
问题描述
我想使用我的java代码导出我的MySQL数据库。但我还没有找到任何办法。我想要做的是我的应用程序中有一个按钮作为导出数据库。单击该按钮时,应将我的数据库导出到指定的路径。我使用了以下代码,但它不起作用:
I want to export my MySQL database using my java code. But I have not found any way to do. What I want to do that there is a button in my app as "Export Database". When that button is clicked, my database should be exported to specified path. I have used the following code but it does'nt worked :
Runtime runtime = Runtime.getRuntime();
runtime.exec("C:\\Program Files\\MySql\\MySql Server 5.5\\bin\\mysqldump -u root -p myDatabase> D:\\backup.sql");
我该如何完成这项任务。谢谢。
How should I do this task. Thanks.
推荐答案
两个问题:
- -p和密码之间的空格
- 可执行文件路径中的空间
首选:
runtime.exec(new String[]{"C:\\Program Files\\MySql\\MySql Server 5.5\\bin\\mysqldump", "-u", "root", "-pmyDatabase" "> D:\\backup.sql"});
请注意,如果你遇到runtime.exec的问题,你应该看一下你可以得到的流来自返回的流程。如果出现错误,不查看这些流有点像没有在抛出异常时查看异常。
Note that if you have a problem with runtime.exec, you should look at the streams you can get from the returned Process. Not looking at those streams in case of error is a little like not looking at the exception when one is thrown.
这篇关于通过我的java代码导出数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!