ant sql 任务抛出“没有可用的结果集”使用 org.sqlite.JDBC 驱动程序
我正在尝试使用 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的 Ant 时,DDL(数据定义语言,例如
CREATE
、DROP
等)语句不返回ResultSet
脚本显然正在期待它。至少,SQLException
基本上告诉了您这一点。我不广泛使用 Ant,因此无法详细介绍,但您至少需要更改脚本,以便无返回值。DDL (Data Definition Language, e.g.
CREATE
,DROP
, etc) statements does not return aResultSet
while your Ant script is apparently expecting it. At least, theSQLException
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.