开发者

java database backup and restore

How do I backup / restore any kind of databases inside my java application to flate files.Are there any tools framework available to backup database to flat file like CSV, XML, or secure encrypted file, or restore from csv or xml file开发者_运维知识库s to databases, it should be also capable of dumping table vise restore and backup also.


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:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜