首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有关Win7问题的MySQL代码的mysqldump

有关Win7问题的MySQL代码的mysqldump
EN

Stack Overflow用户
提问于 2012-05-24 15:09:58
回答 1查看 422关注 0票数 1

好吧,我的Java应用程序不能使用windows运行时环境执行mysqldump备份。我有用于捕获异常的打印输出代码,并且我没有看到异常被抛出,当备份代码被执行时,在表面上看起来很好。

我还在命令行控制台中测试了mysqldump命令;在那里它可以正常工作。

代码:

代码语言:javascript
复制
Runtime rt = Runtime.getRuntime();
try {
    Process pr = rt.exec("mysqldump -u test --password=pass lager > newBackup.sql");

} catch (IOException ex) {
     System.out.println("IO error Runtime.  "+ex.getMessage());
}

有人知道为什么它不转储/备份数据库吗?是否需要添加某些权限或其他内容(运行Windows7)。

EN

回答 1

Stack Overflow用户

发布于 2015-07-18 20:24:05

也许你可以看看这篇文章关于beetwen exec和命令行(http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html)的区别。

在我这边,我尝试使用以下代码来捕获mysqldump的输出--help命令,并将类StreamGoggle find放入来自javaworld的文章中:

代码语言:javascript
复制
    public Main() {
    try {
        FileOutputStream fos = new FileOutputStream("c:/tmp/test.txt");
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec("mysqldump --help");
        // any error message?
        StreamGobbler errorGobbler = new StreamGobbler(
                proc.getErrorStream(), "ERROR");

        StreamGobbler outputGobbler = new StreamGobbler(
                proc.getInputStream(), "OUTPUT", fos);

        errorGobbler.start();
        outputGobbler.start();

        int exitVal = proc.waitFor();
        System.out.println("ExitValue: " + exitVal);
        fos.flush();
        fos.close();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10732784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档