我正在尝试使用 java 恢复一个 mysql sql 文件,但我不知道它为什么不起作用。代码如下。
/*NOTE: Getting path to the Jar file being executed*/
CodeSource codeSource = DBmanager.class.getProtectionDomain().getCodeSource();
File jarFile = new File(codeSource.getLocation().toURI().getPath());
String jarDir = jarFile.getParentFile().getPath();
/*NOTE: Creating Database Constraints*/
String dbName = "dth";
String dbUser = "root";
String dbPass = "root";
String restorePath ="\""+ jarDir + "\\backup" + "\\" + s+"\"";
/*NOTE: Used to create a DOS command*/
String executeCmd = "";
executeCmd = "C:\\xampp\\mysql\\bin\\mysql -u" + dbUser + " -p" + dbPass + " --database " + dbName + " < " + restorePath;
System.out.println(executeCmd);
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
JOptionPane.showMessageDialog(null, "Successfully restored from SQL : " + s);
} else {
JOptionPane.showMessageDialog(null, "Error at restoring");
}
代码执行,但 java swing 卡在运行时命令上。System.out.println 输出的行是这样的。
C:\xampp\mysql\bin\mysql -uroot -proot --database dth < "F:\Final Year Project\Final\build\backup\0_Harish_2013-02-17-20-05-12.sql"
如果我将其复制并粘贴到命令行中,该行将完美运行。不知道为什么 java swing 接口卡在等待状态。(相同的查询在 cmd 上需要 2 秒,在 java 上我已经等了 5 分钟)。
编辑: 我运行了 streamgobbler 仍然没有任何好处,它仍然给出 Exit Value: 1 这显然是问题 IllegalThreadStateException 我该如何解决这个问题?
编辑2:
狼吞虎咽无济于事,因为挂起仍然存在,这是狼吞虎咽的输出
OUTPUT>C:\xampp\mysql\bin\mysql Ver 14.14 Distrib 5.5.27, for Win32 (x86)
OUTPUT>Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
OUTPUT>
OUTPUT>Oracle is a registered trademark of Oracle Corporation and/or its
OUTPUT>affiliates. Other names may be trademarks of their respective
OUTPUT>owners.
OUTPUT>
OUTPUT>Usage: C:\xampp\mysql\bin\mysql [OPTIONS] [database]
OUTPUT> -?, --help Display this help and exit.
OUTPUT> -I, --help Synonym for -?
OUTPUT> --auto-rehash Enable automatic rehashing. One doesn't need to use
OUTPUT> 'rehash' to get table and field completion, but startup
OUTPUT> and reconnecting may take a longer time. Disable with
OUTPUT> --disable-auto-rehash.
OUTPUT> (Defaults to on; use --skip-auto-rehash to disable.)
OUTPUT> -A, --no-auto-rehash
OUTPUT> No automatic rehashing. One has to use 'rehash' to get
OUTPUT> table and field completion. This gives a quicker start of
OUTPUT> mysql and disables rehashing on reconnect.
OUTPUT> --auto-vertical-output
OUTPUT> Automatically switch to vertical output mode if the
OUTPUT> result is wider than the terminal width.
OUTPUT> -B, --batch Don't use history file. Disable interactive behavior.
OUTPUT> (Enables --silent.)
OUTPUT> --character-sets-dir=name
OUTPUT> Directory for character set files.
OUTPUT> --column-type-info Display column type information.
OUTPUT> -c, --comments Preserve comments. Send comments to the server. The
OUTPUT> default is --skip-comments (discard comments), enable
OUTPUT>
(其余使用信息省略)