繁体   English   中英

dbunit / unitils:如何导出多方案数据集?

[英]dbunit/unitils: how to export a multi-schema dataset?

dbunit的官方教程已经为从单个数据库模式导出数据集提供了一个很好的示例
有什么方法可以将来自不同架构的不同表导出到一个单一的数据集中(例如,schema_A中的Table_A,schema_B中的Table_B)?
将导出的数据集写入xml文件时,将如下所示:

<?xml version='1.0' encoding='UTF-8'?>
<dataset schema:schemaA schema:schemaB>
    <schemaA:tableA ..... />
    <schemaA:tableA ..... />
    <schemaB:tableB ..... />
</dataset>

我遇到了同样的问题,要解决此问题,您需要设置FEATURE_QUALIFIED_TABLE_NAMES属性:

看到下面相同的示例代码,但有更改(我删除了部分代码,因为我不需要完整的数据库导出):

    public static void main(String[] args) throws Exception
    {
        // database connection
        Class driverClass = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:sqlserver://<server>:1433;DatabaseName=<dbName>", "<usr>", "<passwd>");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

        Properties props = new Properties();
        props.put(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, "true");
        connection.getConfig().setPropertiesByString(props);        


        // dependent tables database export: export table X and all tables that
        // have a PK which is a FK on X, in the right order for insertion
        String[] depTableNames = TablesDependencyHelper.getAllDependentTables( connection, "vehicle.Vehicle_Series_Model_SMA" );
        IDataSet depDataset = connection.createDataSet( depTableNames );
        FlatXmlDataSet.write(depDataset, new FileOutputStream("vehicle.Vehicle_Series_Model_SMA.xml"));          

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM