java中的数据库

时间:2011-01-04 14:13:47

标签: java ant jdbc hsqldb

我创建了我的build.xml文件夹,它创建了与database(startdb,stopdb,createtable,droptable,startManager)的连接...我运行这个并且他告诉我他按下createtable时创建了表但是当我启动startManager时我看到表没有不存在......如果有人可以帮助我

我的build.xml:

    

    <property file="build.properties" />

    <!-- Global properties for this build. -->
    <property name="database.dir" value="database" />
    <property name="lib.dir" value="lib" />

    <!-- Classpath declaration. -->
    <path id="lib.class.path">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!-- Start the HSQL DB server -->
    <target name="startdb" description="Run HSQL database server with clean DB">
        <!-- Delete database files -->
        <delete dir="${database.dir}" />
        <java classname="org.hsqldb.Server" fork="yes" classpathref="lib.class.path" failonerror="true">
            <arg value="-database.0" />
            <arg value="file:${database.dir}/db" />
        </java>
    </target>

    <!-- Start the HSQL DB browser tool -->
    <target name="startManager" description="Start HSQL DB manager">
        <java classname="org.hsqldb.util.DatabaseManagerSwing" fork="yes" classpathref="lib.class.path" failonerror="true">
            <arg value="-url" />
            <arg value="${db.url}" />
            <arg value="-driver" />
            <arg value="${db.driver}" />
        </java>
    </target>

    <!-- Stop the HSQL DB server -->
    <target name="stopdb" description="Stop HSQL database server">
        <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue">
            <classpath refid="lib.class.path" />
            SHUTDOWN;
        </sql>
    </target>

    <target name="createTables">
        <echo message="CREATE TABLES USING: ${db.driver} ${db.url}" />
        <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue">
            <classpath refid="lib.class.path" />
            CREATE TABLE SALARIATII(
                CNP INTEGER NOT NULL PRIMARY KEY,
                NUME VARCHAR(40) NOT NULL,
                SALAR INTEGER NOT NULL,
                GRADDIDACTIC VARCHAR(256) NOT NULL,
                DATANASTERII VARCHAR(40) NOT NULL
            );
            </sql>
    </target>

    <target name="dropTables">
        <echo message="DROP TABLES USING: ${db.driver} ${db.url}" />
        <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}" onerror="continue">
            DROP TABLE SALARIATII;
            <classpath refid="lib.class.path" />
         </sql>
    </target>

    <target name="emptyTables">
        <echo message="USING: ${db.driver} ${db.url}" />
        <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}">
            <classpath refid="lib.class.path" />
            DELETE FROM SALARIATII;
        </sql>
    </target>


    <target name="populateTables">
        <echo message="USING: ${db.driver} ${db.url}" />
        <sql driver="${db.driver}" url="${db.url}" userid="${db.user}" password="${db.pw}">
            <classpath refid="lib.class.path" />
            INSERT INTO SALARIATII(CNP, NUME,SALAR,GRADDIDACTIC,DATANASTERII) VALUES ( 1,'FLORIN BOIAN',2500,'PROFESOR', '07/08/1950');

        </sql>

    </target>

    <target name="all" depends="dropTables,createTables,emptyTables,populateTables" />

</project>

1 个答案:

答案 0 :(得分:0)

如果droptables在startManager之前运行,那么它会删除表,对吗?也许你真的不想运行droptables?