当前位置:文档之家 > 使用Dbunit来备份恢复数据库

使用Dbunit来备份恢复数据库

package com.rxc.ftp;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.Writer;

import java.sql.Connection;

import java.sql.SQLException;

import org.dbunit.DatabaseUnitException;

import org.dbunit.database.DatabaseConnection;

import org.dbunit.database.IDatabaseConnection;

import org.dbunit.database.QueryDataSet;

import org.dbunit.dataset.CachedDataSet;

import org.dbunit.dataset.DataSetException;

import org.dbunit.dataset.IDataSet;

import org.dbunit.dataset.stream.IDataSetProducer;

import org.dbunit.dataset.stream.StreamingDataSet;

import org.dbunit.dataset.xml.FlatXmlDataSet;

import org.dbunit.dataset.xml.FlatXmlProducer;

import org.dbunit.dataset.xml.XmlDataSetWriter;

import org.dbunit.dataset.xml.XmlProducer;

import org.dbunit.operation.DatabaseOperation;

import org.dbunit.util.FileHelper;

import org.xml.sax.InputSource;

import com.rxc.jdbc.DBConnection;

public class TestDbunit {

/**

* 导出数据到指定文件

* @param file 一个标准的java.io.File

* @param connection 一个标准的java.sql.Conne
ction

* @param connection 一个标准的java.sql.Connection

* @throws org.dbunit.DatabaseUnitException

*/

public static void exportRoom(File file, Connection connection) throws DatabaseUnitException, IOException {

IDatabaseConnection databaseConnection = new DatabaseConnection(connection);

QueryDataSet dataSet = new QueryDataSet(databaseConnection);

dataSet.addTable("AMIS_CLASS");

Writer writer = new FileWriter(file);

下载Word文档免费下载:

使用Dbunit来备份恢复数据库下载

(共3页)