Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Workshop8.1中使用ANT自动执行Sql

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

这是个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)
);



相关文章

相关软件