0

我的 build.xml

<?xml version='1.0'?> 
<project xmlns:ivy="antlib:org.apache.ivy.ant" name='myTest' basedir='.' default='usage'> 
<property file='build.properties' /> 
<property name='src.dir' value='src' /> 
<property name='web.dir' value='war' /> 
<property name='build.dir' value='${web.dir}/WEB-INF/classes' /> 
<property name='name' value='myTest' />
<property name="sql.driver" value="org.postgresql.Driver"/>
<property name="sql.url" value="jdbc:postgresql://localhost:5432/tbook"/>
<property name="sql.user" value="postgres"/>
<property name="sql.pass" value="admin"/>
<path id='master-classpath'> 
    <fileset dir='${web.dir}/WEB-INF/lib'> 
        <include name='*.jar' /> 
    </fileset> 
    <!-- We need the servlet API classes: --> 
    <!-- * for Tomcat 5/6 use servlet-api.jar --> 
    <!-- * for other app servers - check the docs --> 
    <fileset dir='${appserver.lib}'> 
        <include name='servlet*.jar' /> 
    </fileset> 
    <pathelement path='${build.dir}' /> 
</path> 
<target name='usage'> 
    <echo message='' /> 
    <echo message='${name} build file' /> 
    <echo message='-----------------------------------' /> 
    <echo message='' /> 
    <echo message='Available targets are:' /> 
    <echo message='' /> 
    <echo message='build --> Build the application' /> 
    <echo message='deploy --> Deploy application as directory' /> 
    <echo message='deploywar --> Deploy application as a WAR file' /> 
    <echo message='resolve --> retrieve dependencies with ivy' />
    <echo message='' /> 
</target>
<target name="createDB_PostgreSQl">
      <sql driver="${sql.driver}" 
           url="${sql.url}" 
           userid="${sql.user}" 
           password="${sql.pass}"
           src="db.sql">
           <classpath refid="master-classpath"/>
    </sql>
   </target>

   <target name="dropDB_PostgreSQl">
      <input message="Do you really want to delete this table (y/n)?" validargs="y,n" addproperty="do.delete" /> 
      <condition property="do.abort"> 
            <equals arg1="n" arg2="${do.delete}"/> 
      </condition> 
      <fail if="do.abort">Build aborted by user.</fail> 
      <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
           <classpath>
            <pathelement location="postgresql-9.0-802.jdbc4.jar"/>
           </classpath>  
           drop database sample_project;
      </sql>
   </target>
<target name="createTables_PostgreSQL">
      <sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
           <classpath refid="master-classpath"/>
           <transaction src="user.sql"/>
      </sql>
   </target>
<target name='build' description='Compile main source tree java files'> 
    <mkdir dir='${build.dir}' /> 
    <javac destdir='${build.dir}' source='1.5' target='1.5' debug='true' 
        deprecation='false' optimize='false' failonerror='true'> 
        <src path='${src.dir}' /> 
        <classpath refid='master-classpath' /> 
    </javac> 
</target>

<target name="clean">
    <delete includeemptydirs="false">
        <fileset dir="build/" includes="**/**"/>
    </delete>
</target>

<target name='deploy' depends='build' description='Deploy application'> 
    <copy todir='${deploy.path}/${name}' preservelastmodified='true'> 
        <fileset dir='${web.dir}'> 
            <include name='**/*.*' /> 
        </fileset> 
    </copy> 
</target>


<target name="resolve" description="retrieve dependencies with ivy">
        <ivy:retrieve />
</target>

<target name='deploywar' depends='build' 
    description='Deploy application as a WAR file'> 
    <war destfile='${name}.war' webxml='${web.dir}/WEB-INF/web.xml'> 
        <fileset dir='${web.dir}'> 
            <include name='**/*.*' /> 
        </fileset> 
    </war> 
    <copy todir='${deploy.path}' preservelastmodified='true'> 
        <fileset dir='.'> 
            <include name='*.war' /> 
        </fileset> 
    </copy> 
</target> 
</project>

例外是:

org.postgresql.util.PSQLException:ERROR: CREATE DATABASE 不能在事务块内执行

4

1 回答 1

4

看看过去的这个线程。http://archives.postgresql.org/pgsql-jdbc/2005-11/msg00132.php

基本上对于创建数据库任务添加这个 autocommit="true"

于 2012-07-28T22:06:06.823 回答