欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java还原mysql

程序员文章站 2022-05-10 16:58:08
...
	public boolean restore(BackupDto dto) throws Exception {
		OutputStream out = null;
		BufferedReader br = null;
		OutputStreamWriter writer = null;
		try {
			String fPath = dto.getPath();
			Runtime rt = Runtime.getRuntime();

			String rootPath = WebUtil.getMysqlRoot();
			logger.debug("My SQL bin path:" + rootPath);
			String s = "" + rootPath+"bin\\mysql.exe -uroot -p123 logistics";
			
			Process child = rt.exec(s);
			out = child.getOutputStream();// 控制台的输入信息作为输出流
			String inStr;
			StringBuffer sb = new StringBuffer("");
			String outStr;
			br = new BufferedReader(new InputStreamReader(
					new FileInputStream(fPath), "utf8"));
			while ((inStr = br.readLine()) != null) {
				sb.append(inStr + "\r\n");
			}
			outStr = sb.toString();

			writer = new OutputStreamWriter(out, "utf8");
			writer.write(outStr);
			writer.flush();
			out.close();
			br.close();
			writer.close();

			logger.info("restore successfully.");

		} catch (Exception e) {
			logger.error(e);
			return false;
		} finally {
			out.close();
			br.close();
			writer.close();

		}
		return true;

	} 
相关标签: Java MySQL SQL