tags:

views:

1410

answers:

3

I have the following ant build.xml:

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

<property name="pathvar" refid="antclasspath" />
<echo message="Classpath is ${pathvar}"/>

<sql
    driver="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@myserver.hu:1521:dbid"
    userid="myuserid"
    password="mypassword"
    print="yes"
    classpathref="antclasspath">
    select * from table
</sql>

There is an Oracle JDBC driver in the lib directory. Echo prints it out correctly:

Classpath is E:\MyDir\lib\ojdbc14-10_2_0_3.jar

Somehow sql ant task is still not able to load the Oracle driver:

E:\MyDir\build.xml:100: Class Not Found: JDBC driver oracle.jdbc.driver.OracleDriver could not be loaded

What is the problem with this build.xml? It is quite strange that it was working few times yesterday, but never again.

Using classpath="E:\MyDir\lib\ojdbc14-10_2_0_3.jar" in the task gives the same error message.

I'm using ant 1.7.1 (built in Netbeans 6.5)

A: 

Instead of the classpathref attribute you could try using classpath element.

<sql ..params..>
  <classpath refid="antclasspath"/>
</sql>

This is how I always reference my classpaths and I have never had any issues.

Mark
Thanks for the tip. Unfortunately I've got the same error message.
asalamon74
+1  A: 

Try changing the class name to oracle.jdbc.OracleDriver. The oracle.jdbc.driver package is being deprecated in favour of oracle.jdbc.

See the section "The Old oracle.jdbc.driver Package Will Go Away" in the readme here.

Mark
Does not help. The error message changes according to the rename.
asalamon74
+2  A: 

The syntax looks correct to me. Try passing the -v switch to your ant command, that will direct the sql task to print out the classpath it's using. You should see something like:

[sql] connecting to jdbc:oracle:thin:@myserver.hu:1521:dbid
[sql] Loading oracle.jdbc.driver.OracleDriver using AntClassLoader with classpath E:\MyDir\lib\ojdbc14-10_2_0_3.jar
[sql] Executing commands
[sql] SQL:  select * from dual
[sql] Processing new result set.
[sql] DUMMY
[sql] X

[sql] 0 rows affected
[sql] 0 rows affected
[sql] Committing transaction
[sql] 1 of 1 SQL statements executed successfully

If that doesn't help, you can try passing the -debug switch, which will print out reams of information including classloader debugging.

Finally, have you verified that your ojdbc jar is not corrupt and does, in fact, contain the OracleDriver class?

Jason Day
Yes, the jar file was corrupted -v switch gave me an error message. Thanks.
asalamon74