使用dbunit向数据库中插入xml数据

来源:互联网 发布:sql server 列转行 编辑:程序博客网 时间:2024/05/21 05:55
 java code:

IDatabaseConnection connection = null;
      try {
            if(schema !=null && schema.trim().length()>0)
                connection = new DatabaseConnection(DriverManager.getConnection(url, user, password),schema);
            else
                connection = new DatabaseConnection(DriverManager.getConnection(url, user, password));
            File dataFile = new File(resource);
            if(!dataFile.exists() || !dataFile.isFile()){
                throw new IllegalArgumentException("invalidate dataset file.");
            }
            IDataSet dataSet = new FlatXmlDataSet(dataFile);
            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
        } finally{
            if(connection != null){
                connection.close();
            }
        }

xml:
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
    <table_name colName="value" [colName="value"]  />
</dataset>
原创粉丝点击