ant sql 任务使用 org.sqlite.JDBC 驱动程序抛出“没有可用的 ResultSet”

Posted

技术标签:

【中文标题】ant sql 任务使用 org.sqlite.JDBC 驱动程序抛出“没有可用的 ResultSet”【英文标题】:ant sql task throws "no ResultSet available" with org.sqlite.JDBC driver 【发布时间】:2010-02-08 12:02:07 【问题描述】:

我正在尝试使用 org.sqlite.JDBC 在 ant 中创建和更新 sqlite 数据库。 sqlitejdbc-v056.jar来自http://www.zentus.com/sqlitejdbc/,是最新版本(056)

这是我的 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>

这是我得到的输出:

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】:

DDL(数据定义语言,例如 CREATEDROP 等)语句确实返回 ResultSet,而您的 Ant 脚本显然期待它。至少,SQLException 基本上是在告诉你。我没有广泛地做 Ant,所以我不能详细介绍,但您至少需要更改脚本,以便 no 预期返回值。

【讨论】:

这意味着我不能将 sql ant 任务与 DDL 语句一起使用。不是我希望的答案。 :-( 我会接受这个答案,即使它说“这不起作用”。我担心这是唯一正确的答案。

以上是关于ant sql 任务使用 org.sqlite.JDBC 驱动程序抛出“没有可用的 ResultSet”的主要内容,如果未能解决你的问题,请参考以下文章

使用 Ant 任务为 Oracle 配置 worklight Server 失败

ant sql task:复杂的CLOB内容导致异常

sql ant task vs sqlplus:保留词“rem”

Java实现数据库备份并利用ant导入SQL脚本

如何使用 ANT 任务从 SVN 结帐?

如何从 Ant 'exec' 任务中导出环境变量?