????DBUnit?????????????????????? ???????????????????????????????? ????????????????XML?????? ????:
<?xmlversion='1.0'encoding='UTF-8'?>
<dataset>
<YourTableName_1Field_1="1"Field_2="f2"Field_3="f3"/>
<YourTableName_1Field_1="2"Field_2="f2_1"Field_3="f3_1"/>
<YourTableName_2Field_1="1"Field_2="2"/>
</dataset>
????DBUnit?????XML????????У???????????????????????????????????XML?????????????????????. ??????????????????????????
protected ReplacementDataSet createDataSet(InputStream is) throws Exception {
return new ReplacementDataSet(new FlatXmlDataSetBuilder().build(is));
}
ReplacementDataSet createDataSet = createDataSet(Thread.currentThread().getContextClassLoader().getResourceAsStream("data.xml"));
DatabaseOperation.INSERT.execute(iconn?? createDataSet);
????????????XML????????????????????????????????????????棬???DBUnit?????????XML????????????????ε?????????????????????????????????XML?????
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<YourTableName_1 Field_1="1" Field_2="f2"/>
<YourTableName_1 Field_1="2" Field_2="f2_1" Field_3="f3_1"/>
<YourTableName_2 Field_1="1" Field_2="2"/>
</dataset>

????Table YourTableName_1????????Σ?????????????Field_3????????????????????XML?????????д???????DBUnit????в?????????????????????????????????????DBUnit?????η?????table YourTableName_1????????????????????Σ??????????table YourTableName_1????ε??????????????????????????????????????????????????????????????????????????????Σ???????????????????????????С?????????????????YourTableName_1?????????????????????????λ?ú???? ??????????result???????????????????????????????ò???????????????????????

???????????????????????????????????????鷳????????????????????????????????????????DBUnit???????????????е?????????????????У??????????????????????????????????????
/**
* Export data for the table names by the given IDatabaseConnection into the resultFile.<br>
* The export data will be DBUnit format.
*
* @param conn
* @param tableNameList
* @param resultFile
* @throws SQLException
* @throws DatabaseUnitException
* @throws FileNotFoundException
* @throws IOException
*/
public void exportData(IDatabaseConnection iconn?? List<String> tableNameList?? String resultFile) throws SQLException?? DatabaseUnitException?? FileNotFoundException?? IOException {
QueryDataSet dataSet = null;
if (iconn == null) {
return;
}
if (tableNameList == null || tableNameList.size() == 0) {
return;
}
try {
dataSet = new QueryDataSet(iconn);
for (String tableName : tableNameList) {
dataSet.addTable(tableName);
}
} finally {
if (dataSet != null) {
FlatXmlDataSet.write(dataSet?? new FileOutputStream(resultFile));
}
}
}
????DBUnit????????????????????????н?????б??????????????????н?????????? ??????????????????????????XML???????????????????????????SQL????????????????????????????????????н????SQL????????????????????ε?ORDER BY?????????????????????????????????DBUnit????????????????????????????????????????????SQL????????????????????????XML????????????????????????????????????????????????????????????
???????????????????????????????? ū???????????????????????????????DBUnit??????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????