MySql数据库导入不适用于java web应用程序
我想使用java on web应用程序导入mysql数据库,但不幸的是mysql.exe进程被卡住,下一行代码无法执行,这使得浏览器无法继续加载 restore.xhtmlMySql数据库导入不适用于java web应用程序,java,mysql,web-applications,import,Java,Mysql,Web Applications,Import,我想使用java on web应用程序导入mysql数据库,但不幸的是mysql.exe进程被卡住,下一行代码无法执行,这使得浏览器无法继续加载 restore.xhtml <h:panelGrid columns="1" style="margin: 0 auto;"> <p:commandButton value="1 click restore" action="#restoreBean.oneClickRestore()}" update=
<h:panelGrid columns="1" style="margin: 0 auto;">
<p:commandButton value="1 click restore"
action="#restoreBean.oneClickRestore()}" update="all,g" ajax="false"/>
</h:panelGrid>
但在控制台应用程序中使用时,同样的代码运行良好,并且可以导入数据库
RestoreDbTest.java
String absPath ="C:/Users/sms/build/web/resources/backup/backuproot.sql";
String[] executeCmd = new String[]{"mysql ", dbName, "-u " + dbUser, "-p " + dbPwd, "-e ", " \"source "+ absPath+" \""};
try{
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();// after this line no line of code get executed; in taskmanager u can see mysql.exe
if (processComplete == 0) {
restoreMsg = "Successfully restored from SQL : " + absPath;
} else {
restoreMsg = "Error at restoring";
}
} catch (InterruptedException ex) {
Logger.getLogger(RestoreBean.class.getName()).log(Level.SEVERE, null, ex);
}
public class RestoreDbTest{
public static void main(String[] args) {
RestoreDbTest b = new RestoreDbTest();
b.restoreDatabase("root", "", "b.sql");
}
public boolean restoreDatabase(String dbUserName, String dbPassword, String source) {
String[] executeCmd = new String[]{"mysql ", dbName, "-u " + dbUser, "-p " + dbPwd, "-e ", " \"source b.sql \""};
Process runtimeProcess;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
// log.info("Backup restored successfully with " + source);
return true;
} else {
//log.info("Could not restore the backup " + source);
}
} catch (Exception ex) {
System.out.println(ex.getCause());
}
return false;
}
}
mysql进程列表
您是否测试了从系统命令行生成的mysql命令,以查看它是否会执行?另外,查看mysql中正在运行的命令(不知道它应该运行多长时间,但是使用
showProcessList
您可能会看到一些东西)在命令行中,它工作得很好,甚至在java控制台应用程序中,同样的代码也工作得很好,但在web中,我不知道为什么事情不顺利。您是否测试了从系统的命令行生成的mysql命令,以查看它是否随后执行?另外,请查看mysql中正在运行的命令(不知道它应该运行多长时间,但使用show processlist
您可能会看到一些东西),在命令行中,它工作正常,甚至在java控制台应用程序中,相同的代码也工作正常,但在web中,我不知道为什么事情进展不顺利