- dbunit-2.4.7
- slf4j-api-1.6.1
- slf4j-simple-1.6.1
- mysql-connector-java-5.0.8
Example program:
import java.io.FileOutputStream; import java.sql.*; import org.dbunit.database.*; import org.dbunit.dataset.*; import org.dbunit.dataset.xml.*; // database connection Class driverClass = Class.forName("com.mysql.jdbc.Driver"); Connection jdbcConnection = DriverManager.getConnection("jdbc:mysql://host:port/dbname","user","pass"); IDatabaseConnection connection = new DatabaseConnection(jdbcConnection); // prevent error: Potential problem found: The configured data type factory // 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'MySQL' // (e.g. some datatypes may not be supported properly). connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory()); // full database export IDataSet fullDataSet = connection.createDataSet(); FlatXmlDataSet.write(fullDataSet, new FileOutputStream("dbname"));