简体   繁体   English

java数据库备份与还原

[英]java database backup and restore

如何将Java应用程序中的任何数据库备份/还原为平面文件。是否有任何工具框架可用于将数据库备份至CSV,XML或安全加密文件等平面文件,或从csv或xml文件还原至数据库,它还应该能够转储表台钳还原和备份。

There are many ways to do this. 有很多方法可以做到这一点。 It really depends on how complicated your "database" is. 这实际上取决于您的“数据库”的复杂程度。

The simplest solution is to write to a text file in a CSV format: 最简单的解决方案是以CSV格式写入文本文件:

import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;


public class FileOutput {

  public static void main(String[] args) {

    File file = new File("C:\\MyFile.csv");
    FileOutputStream fis = null;
    PrintWriter output = null;

    try {
      fos = new FileOutputStream(file);
      output = new PrintWriter(fos);

      output.println("Column A, Column B, Column C");

      // dispose all the resources after using them.
      outputStream.flush();
      fos.close();
      outputStream.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Or, if you're looking for an XML solution, you can play with Xerces API, which I think is included in the latest JDK, so you just have to include the packages. 或者,如果您正在寻找XML解决方案,则可以使用Xerces API(我认为它包含在最新的JDK中),因此您只需要包括这些软件包即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM