zoukankan      html  css  js  c++  java
  • ant+dbunit 导xml到mysql

    1.增加自己的data目录和xml数据文件

    2.lib依赖

    • commons-logging-1.1.1.jar
    • dbunit-2.4.8.jar
    • junit-4.9b2.jar
    • mysql-connector-java-3.1.12-bin.jar
    • slf4j-api-1.6.1.jar
    • slf4j-jcl-1.6.1.jar

    3.ant文件如上

     1 <?xml version="1.0"  encoding="UTF-8"?>
     2 
     3 <project name="project" default="" basedir=".">
     4 
     5     <property name="lib" value="lib" />
     6     <property name="conf" value="conf" />
     7     <property name="dbunit.operation.type" value="REFRESH" />
     8     <!--CLEAN_INSERT,REFRESH-->
     9     
    10     <property environment="env" />
    11 
    12     <!--本地环境-->
    13     <property file="${conf}/application.properties" />
    14 
    15     <!--linux环境-->
    16     <property file="${env.TX_CONF_PATH}/application.properties" />
    17 
    18     <path id="lib.path">
    19       <pathelement location="${conf}"/>
    20         <fileset dir="${lib}">
    21             <include name="**/*.jar" />
    22         </fileset>
    23     </path>
    24 
    25     <!-- load init data -->
    26     <target name="load" description="load test data into db">
    27         <echo message="更新数据库中的策划配数数据 到 ${env.TX_CONF_PATH}" />
    28         <taskdef name="dbunit" classname="org.dbunit.ant.DbUnitTask" classpathref="lib.path">
    29         </taskdef>
    30         <!--REFRESH  CLEAN_INSERT-->
    31         <dbunit driver="com.mysql.jdbc.Driver" url="jdbc:mysql://${mysql.dbServer}?useUnicode=true&amp;characterEncoding=UTF-8&amp;rewriteBatchedStatements=true" userid="${mysql.user}" password="${mysql.passwd}" supportBatchStatement="true" >
    32             <!-- type可选择的方式 删除、清空插入、追加   UPDATE, INSERT, REFRESH, DELETE, DELETE_ALL, CLEAN_INSERT-->
    33             <operation type="${dbunit.operation.type}" src="data/Entity.xml" />
    34             <operation type="${dbunit.operation.type}" src="data/EntityConsume.xml" />
    35             <operation type="${dbunit.operation.type}" src="data/EntityLimit.xml" />
    36             <operation type="${dbunit.operation.type}" src="data/Effect.xml" />
    37             <operation type="${dbunit.operation.type}" src="data/SysPara.xml" />
    38             <operation type="${dbunit.operation.type}" src="data/DropPack.xml" />
    39             <operation type="${dbunit.operation.type}" src="data/Item.xml" />
    40             <operation type="${dbunit.operation.type}" src="data/Equip.xml" />
    41             <operation type="${dbunit.operation.type}" src="data/Army.xml" />
    42 
    43         </dbunit>
    44     </target>
    45 </project>

     

    4. 运行结果

    Buildfile: E:heartworkspaceRedAlert_v0.1uild.xml
    load:
         [echo] 更新数据库中的策划配数数据 到 ${env.TX_CONF_PATH}
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataEntity.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataEntityConsume.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataEntityLimit.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataEffect.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataSysPara.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataDropPack.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataItem.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataEquip.xml
       [dbunit]           with format: null
       [dbunit] Executing operation: REFRESH
       [dbunit]           on   file: E:heartworkspaceRedAlert_v0.1dataArmy.xml
       [dbunit]           with format: null
    BUILD SUCCESSFUL
    Total time: 25 seconds
  • 相关阅读:
    DTD与shema学习
    xml基本语法学习
    快速写出main方法和system.out.print()
    Eclipse常见快捷键
    System.out.print()与toString()
    HttpURLConnection学习
    如何查看开关机时间
    阿里云云服务器硬盘分区及挂载
    java环境搭建
    使用jstack 发现死锁
  • 原文地址:https://www.cnblogs.com/dagangzi/p/4861495.html
Copyright © 2011-2022 走看看