title: Trying create db using ant
body: <p>My build.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0'?&gt; 
  &lt;project xmlns:ivy="antlib:org.apache.ivy.ant" name='myTest' basedir='.' default='usage'&gt; 
  &lt;property file='build.properties' /&gt; 
  &lt;property name='src.dir' value='src' /&gt; 
  &lt;property name='web.dir' value='war' /&gt; 
  &lt;property name='build.dir' value='${web.dir}/WEB-INF/classes' /&gt; 
  &lt;property name='name' value='myTest' /&gt;
  &lt;property name="sql.driver" value="org.postgresql.Driver"/&gt;
  &lt;property name="sql.url" value="jdbc:postgresql://localhost:5432/tbook"/&gt;
  &lt;property name="sql.user" value="postgres"/&gt;
  &lt;property name="sql.pass" value="admin"/&gt;
  &lt;path id='master-classpath'&gt; 
      &lt;fileset dir='${web.dir}/WEB-INF/lib'&gt; 
          &lt;include name='*.jar' /&gt; 
      &lt;/fileset&gt; 
      &lt;!-- We need the servlet API classes: --&gt; 
      &lt;!-- * for Tomcat 5/6 use servlet-api.jar --&gt; 
      &lt;!-- * for other app servers - check the docs --&gt; 
      &lt;fileset dir='${appserver.lib}'&gt; 
          &lt;include name='servlet*.jar' /&gt; 
      &lt;/fileset&gt; 
      &lt;pathelement path='${build.dir}' /&gt; 
  &lt;/path&gt; 
  &lt;target name='usage'&gt; 
      &lt;echo message='' /&gt; 
      &lt;echo message='${name} build file' /&gt; 
      &lt;echo message='-----------------------------------' /&gt; 
      &lt;echo message='' /&gt; 
      &lt;echo message='Available targets are:' /&gt; 
      &lt;echo message='' /&gt; 
      &lt;echo message='build --&gt; Build the application' /&gt; 
      &lt;echo message='deploy --&gt; Deploy application as directory' /&gt; 
      &lt;echo message='deploywar --&gt; Deploy application as a WAR file' /&gt; 
      &lt;echo message='resolve --&gt; retrieve dependencies with ivy' /&gt;
      &lt;echo message='' /&gt; 
  &lt;/target&gt;
  &lt;target name="createDB_PostgreSQl"&gt;
        &lt;sql driver="${sql.driver}" 
             url="${sql.url}" 
             userid="${sql.user}" 
             password="${sql.pass}"
             src="db.sql"&gt;
             &lt;classpath refid="master-classpath"/&gt;
      &lt;/sql&gt;
     &lt;/target&gt;
  
     &lt;target name="dropDB_PostgreSQl"&gt;
        &lt;input message="Do you really want to delete this table (y/n)?" validargs="y,n" addproperty="do.delete" /&gt; 
        &lt;condition property="do.abort"&gt; 
              &lt;equals arg1="n" arg2="${do.delete}"/&gt; 
        &lt;/condition&gt; 
        &lt;fail if="do.abort"&gt;Build aborted by user.&lt;/fail&gt; 
        &lt;sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" &gt;
             &lt;classpath&gt;
              &lt;pathelement location="postgresql-9.0-802.jdbc4.jar"/&gt;
             &lt;/classpath&gt;  
             drop database sample_project;
        &lt;/sql&gt;
     &lt;/target&gt;
  &lt;target name="createTables_PostgreSQL"&gt;
        &lt;sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" &gt;
             &lt;classpath refid="master-classpath"/&gt;
             &lt;transaction src="user.sql"/&gt;
        &lt;/sql&gt;
     &lt;/target&gt;
  &lt;target name='build' description='Compile main source tree java files'&gt; 
      &lt;mkdir dir='${build.dir}' /&gt; 
      &lt;javac destdir='${build.dir}' source='1.5' target='1.5' debug='true' 
          deprecation='false' optimize='false' failonerror='true'&gt; 
          &lt;src path='${src.dir}' /&gt; 
          &lt;classpath refid='master-classpath' /&gt; 
      &lt;/javac&gt; 
  &lt;/target&gt;
  
  &lt;target name="clean"&gt;
      &lt;delete includeemptydirs="false"&gt;
          &lt;fileset dir="build/" includes="**/**"/&gt;
      &lt;/delete&gt;
  &lt;/target&gt;
  
  &lt;target name='deploy' depends='build' description='Deploy application'&gt; 
      &lt;copy todir='${deploy.path}/${name}' preservelastmodified='true'&gt; 
          &lt;fileset dir='${web.dir}'&gt; 
              &lt;include name='**/*.*' /&gt; 
          &lt;/fileset&gt; 
      &lt;/copy&gt; 
  &lt;/target&gt;
  
  
  &lt;target name="resolve" description="retrieve dependencies with ivy"&gt;
          &lt;ivy:retrieve /&gt;
  &lt;/target&gt;
  
  &lt;target name='deploywar' depends='build' 
      description='Deploy application as a WAR file'&gt; 
      &lt;war destfile='${name}.war' webxml='${web.dir}/WEB-INF/web.xml'&gt; 
          &lt;fileset dir='${web.dir}'&gt; 
              &lt;include name='**/*.*' /&gt; 
          &lt;/fileset&gt; 
      &lt;/war&gt; 
      &lt;copy todir='${deploy.path}' preservelastmodified='true'&gt; 
          &lt;fileset dir='.'&gt; 
              &lt;include name='*.war' /&gt; 
          &lt;/fileset&gt; 
      &lt;/copy&gt; 
  &lt;/target&gt; 
  &lt;/project&gt;
  </code></pre>
  
  <p>Exception is:</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException:ERROR: CREATE DATABASE can not be executed inside a transaction block</p>
  </blockquote>