private void exportFK(String file) throws Exception {
   IDataSet fullDataSet = dbunitConnection.createDataSet();
   ITableFilter filter = new DatabaseSequenceFilter(dbunitConnection);
   FilteredDataSet filteredDatSet = new FilteredDataSet(filter, fullDataSet);
   FlatXmlDataSet.write(filteredDatSet, new FileOutputStream(file + ".xml"));
   FlatDtdDataSet.write(filteredDatSet, new FileOutputStream(file + ".dtd"));
 }
示例#2
0
  public static void main(String[] args) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection =
        DriverManager.getConnection("jdbc:mysql://localhost:3306/dbunit", "root", "1234");
    IDatabaseConnection databaseConnection = new DatabaseConnection(connection);

    // 根据SQL导出部分数据
    QueryDataSet queryDataSet = new QueryDataSet(databaseConnection);
    queryDataSet.addTable("users", "select password from users where id = 10");
    FlatXmlDataSet.write(queryDataSet, new FileOutputStream("dbunitXMLConditation.xml"));

    // 导出整个库的数据
    IDataSet dataSet = databaseConnection.createDataSet();
    // 将dbunit表中的数据写入到dbunitXML.xml文件中
    FlatXmlDataSet.write(dataSet, new FileOutputStream("dbunitXML.xml"));
    FlatDtdDataSet.write(dataSet, new FileOutputStream("dbunitXML.dtd"));
  }
 private void export(String file) throws Exception {
   IDataSet fullDataSet = dbunitConnection.createDataSet();
   FlatXmlDataSet.write(fullDataSet, new FileOutputStream(file + ".xml"));
   FlatDtdDataSet.write(fullDataSet, new FileOutputStream(file + ".dtd"));
 }