views:

334

answers:

1

I'm trying to use org.sqlite.JDBC to create and update a sqlite database in ant. The sqlitejdbc-v056.jar comes from http://www.zentus.com/sqlitejdbc/ and is the latest version (056)

This is my build.xml:

<?xml version="1.0" encoding="utf-8"?>

<project name="My Project" default="mytarget" basedir=".">

    <path id="antclasspath">
        <fileset dir="_ant">
            <include name="*.jar"/>
        </fileset>
    </path>

    <target name="mytarget">
        <property name="antclasspathar" refid="antclasspath" />
        <echo message="Classpath is ${antclasspathar}"/>
        <sql
            driver="org.sqlite.JDBC"
            url="jdbc:sqlite:C:/Projects/dummy/test.db"
            userid=""
            password=""
            classpathref="antclasspath"
        >
            DROP TABLE IF EXISTS people;
            CREATE TABLE people (name, occupation);
        </sql>

    </target>

</project>

This is the output I get:

C:\Projects\dummy>ant -v
Apache Ant version 1.7.1 compiled on June 27 2008
Buildfile: build.xml
Detected Java version: 1.6 in: C:\Program Files (x86)\Java\jdk1.6.0_10\jre
Detected OS: Windows Vista
parsing buildfile C:\Projects\dummy\build.xml with URI = file:/C:/Projects/dummy/build.xml
Project base dir set to: C:\Projects\dummy
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
Build sequence for target(s) `mytarget' is [mytarget]
Complete build sequence is [mytarget, ]

mytarget:
     [echo] Classpath is C:\Projects\dummy\_ant\sqlitejdbc-v056.jar
      [sql] connecting to jdbc:sqlite:C:/Projects/dummy/test.db
      [sql] Loading org.sqlite.JDBC using AntClassLoader with classpath C:\Projects\dummy\_ant\sqlitejdbc-v056.jar
      [sql] Executing commands
      [sql] SQL:  DROP TABLE IF EXISTS people
      [sql] Failed to execute:  DROP TABLE IF EXISTS people

BUILD FAILED
java.sql.SQLException: no ResultSet available
        at org.sqlite.Stmt.getResultSet(Stmt.java:111)
        at org.apache.tools.ant.taskdefs.SQLExec.execSQL(SQLExec.java:567)
        at org.apache.tools.ant.taskdefs.SQLExec.runStatements(SQLExec.java:535)
        at org.apache.tools.ant.taskdefs.SQLExec$Transaction.runTransaction(SQLExec.java:764)
        at org.apache.tools.ant.taskdefs.SQLExec$Transaction.access$000(SQLExec.java:706)
        at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:449)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Total time: 0 seconds
+1  A: 

DDL (Data Definition Language, e.g. CREATE, DROP, etc) statements does not return a ResultSet while your Ant script is apparently expecting it. At least, the SQLException is basically telling that you. I don't do Ant extensively, so I can't go in detail, but you at least need to change the script so so that no return value is expected.

BalusC
This would mean that I can't use the sql ant task with DDL statements. Not the answer I was hoping for. :-(
Kristof Neirynck
I'm going to accept this answer even though it states "this doesn't work". I fear it is the only correct answer.
Kristof Neirynck