Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems Verifying Oracle Drivers

 
Mike Cutter
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you for your reply.

Adding the ":." to the classpath executed the program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic