尝试导入 MYSQL 数据库,但在 BufferedReader.readLine() 方法中遇到问题,它使系统等待某些东西。代码在一段时间后导入数据库备份,但系统总是运行并且readLine方法不允许系统前进,并且在这段代码中输出来了。1 2 3 4 4a 和系统开始等待某事。任何解决方案提前致谢
public static boolean restoreDB(String dbName, String dbUserName, String dbPassword, String source) {
String[] executeCmd = new String[]{"C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysql", "--user=" + dbUserName, "--password=" + dbPassword, "-e", "source \"D:/khokher/medmax.sql\""};
System.out.println("1 Processing Start");
Process runtimeProcess = null;
try {
String line = "";
System.out.println("2");
runtimeProcess = new ProcessBuilder(executeCmd).start();
System.out.println("3");
InputStream istrm = runtimeProcess.getInputStream();
InputStreamReader istrmrdr = new InputStreamReader(istrm);
BufferedReader buffrdr = new BufferedReader(istrmrdr);
System.out.println("4");
String data;
String st;
System.out.println("4a");
while (!(st=buffrdr.readLine()).isEmpty()) { // actual problem is in readLine Method it block system
System.out.println("5 in loop");
}
int ev = 0 ;
System.out.println("7 .waitFor()");
if (runtimeProcess.waitFor() != 0) {
ev = runtimeProcess.exitValue();
System.out.println("8 process exitValue()");
}else{
System.out.println("9 Backup restored successfully");
return true;
}
} catch(InterruptedException e){
e.printStackTrace();
System.out.println("10");
Thread.currentThread().interrupt();
return false;
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("11");
Thread.currentThread().interrupt();
return false;
} finally {
System.out.println("processing stoped");
}
return false;
}