Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java的MySQL数据库还原代码不起作用,使应用程序没有响应_Java_Mysql - Fatal编程技术网

使用java的MySQL数据库还原代码不起作用,使应用程序没有响应

使用java的MySQL数据库还原代码不起作用,使应用程序没有响应,java,mysql,Java,Mysql,这是我的mysql数据库还原代码。当我尝试此代码时,应用程序正常工作,但应用程序挂起,数据库未还原。请帮助我 String databaseName = "sample"; //database name String userName = "root"; // MySQL username String password = ""; // MySQL password int processComplete; // this variable for verify the process S

这是我的mysql数据库还原代码。当我尝试此代码时,应用程序正常工作,但应用程序挂起,数据库未还原。请帮助我

String databaseName = "sample"; //database name
String userName = "root"; // MySQL username
String password = ""; // MySQL password
int processComplete; // this variable for verify the process

String[] executeCmd = new String[]{"C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysql",
        databaseName, "-u" + userName, "-p" + password, "-e", " source D:/data.sql"};

System.out.println(executeCmd);
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);// execute the command
processComplete = runtimeProcess.waitFor();
System.out.println(processComplete);

if (processComplete == 1) { // if return value equal to 1 then failed the process
    JOptionPane.showMessageDialog(null, "Restore Failed");
} else if (processComplete == 0) {{// if return value equal to 0 then failed the process
    JOptionPane.showMessageDialog(null, "Restore Completed");
}

我怀疑最后一个参数处理不当

String[] executeCmd = new String[]{
    "C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysql", 
    databaseName, 
    "-u" + userName, 
    "-p" + password, 
    "-e", 
    " source D:/data.sql" }
它应该看起来更像

String[] executeCmd = new String[]{
    "C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysql", 
    databaseName, 
    "-u" + userName, 
    "-p" + password, 
    "-e", 
    "source", 
    "D:/data.sql" }
数组中的每个元素都是传递给命令的单独参数,这使您可以灵活地传递带有空格的参数,而无需首先使用引号对其进行转义

您应该考虑使用<代码> PrimeBuffer-<代码>,而不是试图建立<代码>进程<代码> >,除了允许您将错误流重新引导到输入流之外,它还允许您指定进程的起始上下文。

您还应该读取进程的输出(通过它的
InputStream
),这可能会突出显示问题,也可能允许进程退出(因为某些进程在完全读取标准输出之前不会退出)


例如:

感谢您的响应,但数据库仍然没有恢复这里是我的代码感谢您的响应,但数据库仍然没有恢复,进程值为1这里是我的代码字符串[]executeCmd=new String[]{“C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysql5.5.24\\mysql4\\mysql”,databaseName,“-u”+用户名,“-p”+密码,“-e”,“source”,“D:/data.sql” }; ProcessBuilder pb=新的ProcessBuilder(executeCmd);重定向错误();进程p=pb.start();InputStreamConsumer isc=新的InputStreamConsumer(p.getInputStream());isc.start();int exitCode=p.waitFor();isc.join();System.out.println(“进程以“+exitCode”终止);我正在使用win7的任何解决方案,
InputStreamConsumer
是否显示任何错误消息?该命令是否在命令行中工作?数据库中没有错误和更改。进程状态为1数据库位于何处?