Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems Verifying Oracle Drivers

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using HP-UX 11.11, Java2 1.4.2.04, and Oracle 9.2.0.5. I wrote a simple program that will just verify the JDBC drivers that is not working.

import java.sql.*;
import java.util.*;

class VerifyDrivers {
public static void main(String args[]) {
String driverClasses[] = {"sun.jdbc.odbc.JdbcOdbcDriver",
"oracle.jdbc.OracleDriver"};
Properties prop = new Properties();
try {
for (int i=0; i<driverClasses.length; i++) {
Class.forName(driverClasses[i]);
}
Enumeration drivers = DriverManager.getDrivers();
System.out.println("Available drivers are:");
while (drivers.hasMoreElements()) {
Driver driver = (Driver) drivers.nextElement();
System.out.println("\n Driver name: " +
driver.getClass().getName());
System.out.println(" JDBC Compliant: " +
driver.jdbcCompliant());
}
} catch (Exception e) {
System.out.println("OOPS! "+e.toString());
System.exit(0);
}
}
}

It compiled fine.
javac -classpath $ORACLE_HOME/jdbc/lib/ojdbc14.jar VerifyDrivers.java

It would not execute:
java VerifyDrivers
OOPS! java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

java -classpath $ORACLE_HOME/jdbc/lib/ojdbc14.jar VerifyDrivers
Exception in thread "main" java.lang.NoClassDefFoundError: VerifyDrivers

I would appreciate some help in learning how to verify the Oracle JDBC drivers. I am not even connecting to the database yet. This program successfully ran with just verifying the JDBC-ODBC driver.

Mike
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't want to use the jdbc-odbc-driver!
Concentrate on the jdbc-driver, ojdbc14.jar.

javac -classpath $ORACLE_HOME/jdbc/lib/ojdbc14.jar VerifyDrivers.java


You don't need to specify the path to ojdb14.jar while compiling, since the Driver is only mentioned in a String, and needn't be present at compile time.

javac doesn't expect to find something to compile in the classpath, and finds your VerifyDrivers.java in the current dir.

java -classpath $ORACLE_HOME/jdbc/lib/ojdbc14.jar VerifyDrivers
Exception in thread "main" java.lang.NoClassDefFoundError: VerifyDrivers


java doesn't find VerifyDrivers - the question whether JdbcOdbc or Ora14 isn't touched at all.
Why?
Because classpath lacks the current directory:
 
Mike Cutter
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.

Adding the ":." to the classpath executed the program.
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic