尝试以下代码:
<sql
classpath="postgresql-8.4-701.jdbc3.jar"
driver="org.database.jdbcDriver"
url="devtest"
userid="uid"
password="pass">
select * from tab where tname = 'GR_DOCUMENT_PRINT_DFV';
</sql>
获得以下错误:
BUILD FAILED
C:\Program Files\Java\apache-ant-1.8.1\build.xml:62: Class Not Found: JDBC driver
org.database.jdbcDriver could not be loaded
Total time: 1 second
请帮忙。
现在我已经更新了代码。将classpath添加到上一个代码。还要将mysql-connector-java-3.0.8-stable-bin.jar和postgresql-8.4-701.jdbc3.jar文件添加到ANT_HOME / lib,但仍会出现相同的错误。
答案 0 :(得分:6)
如果您使用的是Oracle,可以尝试
<path id="antclasspath">
<fileset dir="path-to-lib">
<include name="ojdbc14.jar"/>
</fileset>
</path>
<sql
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@serverip:1521:sid"
userid="userid"
password="password"
print="yes"
classpathref="antclasspath">
select * from tab where tname = 'GR_DOCUMENT_PRINT_DFV';
</sql>
如果仍有相同的错误,请使用-v开关运行ant。这将指示sql任务打印出它正在使用的类路径,你可以验证。
答案 1 :(得分:1)
您应该指定驱动程序的类路径
<sql classpathref="${classpath.id}" driver="" ...
定义你的课程路径
<path id="classpath.id">
<fileset file="..." />
</path>
答案 2 :(得分:1)
包含org.database.jdbcDriver
的jar是否在类路径中?您可能需要添加一个类路径属性
<sql
classpath="mysql-connector-java-3.0.8-stable-bin.jar"
driver="org.database.jdbcDriver"
url="devtest"
userid="uid"
password="pass">
答案 3 :(得分:0)
<sql
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:ENOVIADEV"
userid="sys"
password="enoviaV6"
expandProperties="true"
classpathref="antclasspath">
<connectionProperty name="internal_logon" value="SYSDBA"/>
<transaction>
create tablespace ${TablespaceName} datafile '${DatafilePath}/${DatafileNAME}' size 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
</transaction>
<transaction>
create user ${oracle.dbuser} identified by ${oracle.dbpassword} default tablespace ${TablespaceName} temporary tablespace TEMP;
</transaction>
<transaction>
grant connect, resource, unlimited tablespace to ${oracle.dbuser};
</transaction>
<transaction>
alter user ${Username} default role all;
</transaction>
</sql>