编程语言

img aaronsi

Workshop8.1中使用ANT自动执行Sql

发表于2004/10/1 9:23:00  705人阅读

这是个ant实现自动sql建表的例子,运行方法,在workshop中先建一个java project,倒入这三个文件,Build 这个java project,如果Ant窗口在workshop中没有显示,就选择 察看-〉窗口->ANT

执行sql时双击ANT窗口中的图标既可自动执行。


文件1:build.xml内容如下:
<?xml version="1.0"?>
<!-- =====================================================================
     Author: aaronsi
     Date:  05/25/2004
     ===================================================================== -->

<project name="Database"
         default="resetDB"
         basedir="">

    <property name="pointbase.dir"
              value="pointbase" />            

    <property name="pointbase.port"
              value="9093" />

    <property name="pointbase.db.driver"
              value="com.pointbase.jdbc.jdbcUniversalDriver" />

    <property name="pointbase.db.name"
              value="workshop" />       

    <property name="pointbase.host"
              value="localhost" />

    <property name="weblogic.home"
              value="@WL_HOME" />
          
    <path id="classpath.pointbase">
        <pathelement location="${weblogic.home}/common/eval/pointbase/lib/pbtools44.jar"/>
        <pathelement location="${weblogic.home}/common/eval/pointbase/lib/pbclient44.jar"/>
    </path>

    <target name="resetDB"
            description="Clear and repopulate the database"
            depends="createTables,buildDatabase"/>

    <target name="createTables"
            description="Drop and create the demo tables"
    >
        <antcall target="pbCommand">
            <param name="pbscript"
                   value="dbdemo_init.sql"/>
            <param name="pointbase.db.user"
                   value="weblogic"/>
            <param name="pointbase.db.password"
                   value="weblogic"/>                  
        </antcall>
    </target> 
   
    <target name="buildDatabase"
            description="Populate tables with data"
            depends="createTables">
        <antcall target="pbCommand">
            <param name="pbscript"
                   value="dbdemo_data.sql"/>
            <param name="pointbase.db.user"
                   value="weblogic"/>
            <param name="pointbase.db.password"
                   value="weblogic"/>                  
        </antcall>
    </target>                

    <target name="pbCommand"
            description="Starts the PointBase Client with a SQL script."
    >
            <echo message="${java.class.path}" />
            <echo message="User Dir: ${user.dir}" />
            <echo message="Project Dir: ${basedir}" />           
            <echo message="PB Script to run: ${basedir}/${pbscript}"/>
            <java classname="com.pointbase.tools.toolsCommander">
            <arg value="${pointbase.db.driver}" />
            <arg value="jdbc:pointbase://${pointbase.host}:${pointbase.port}/${pointbase.db.name}" />
            <arg value="${basedir}/${pbscript}" />
            <arg value="${pointbase.db.user}" />
            <arg value="${pointbase.db.password}" />
            <classpath>
                <path refid="classpath.pointbase" />
            </classpath>
        </java>
    </target>

</project> 


文件2:dbdemo_data.sql,内容如下:

insert into DEMO.usertable
(username, age,address) values
('aaron',25,'Beijing'),
('andy', 25,'Shanghai')
;

文件3:dbdemo_init.sql,内容如下:

drop schema DEMO;
create schema DEMO;

create table DEMO.usertable
(
   userid integer identity  not null,
   username varchar2 ( 30),
   age int,
   address varchar2 ( 30),
   constraint PK_CUSTOMER primary key ( userid)
);
阅读全文
0 0

相关文章推荐

img
取 消
img