Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Applets: DriverManager.registerDriver NoClassDefFoundError

Re: Applets: DriverManager.registerDriver NoClassDefFoundError

From: Rauf Sarwar <rs_arwar_at_hotmail.com>
Date: 17 May 2003 16:38:42 -0700
Message-ID: <92eeeff0.0305171538.7b4cdec4@posting.google.com>


dkm32_at_hotmail.com (Donna) wrote in message news:<25032dfc.0305160920.5fc30f5d_at_posting.google.com>...
> Basically, I can get a Java Program to work, but an applet with the
> same code fails. I'm running j2sdk 1.4.1.02 under Windows 2000, with
> Oracle 9i and Internet Explorer 6.0.
>
> CreateJoltData is just a plain Java program; JoltData is an Applet
> (Included below). Both use the same statement to register the Oracle
> Driver. It's the one that is used in all of the books and the Oracle
> webpages:
> DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
>
> I can connect and access an Oracle database from the Java program
> (CreateJoltData)...but not the Applet (JoltData).
>
> If I use the Classpath: .;C:\oracle\ora92\jdbc\lib\classes12_g.zip:
> - The program compiles and executes just fine.
> - The Java Applet compiles but gets a runtime error that usually
> means that the Classpath is not set correctly:
> java.lang.NoClassDefFoundError: orable/jdbc/OracleDriver.
>
> If I use the Classpath: .;C:\oracle\ora92\jdbc\lib\ojdbc14_g.zip
> (which Oracle recommends), both the program and the applet get a
> compile error:
> Package Oracle.jdbc does not exist.
>
> Any help would greatly be appreciated!!!
>
> Donna
>
> ------------------ JoltData.java:
>
> /* JoltData
> compile: javac JoltData.java
> execute: JoltData.html
> */
> import java.applet.*;
> import java.awt.*;
> import java.io.*;
> import java.sql.*;
> import oracle.sql.*;
> import oracle.jdbc.*;
>
> public class JoltData extends Applet {
>
> String database= "Coffee";
> String username = "Donna";
> String password = "v1v1enne";
> Connection conn=null;
>
> // Constructor
> public JoltData () {
> System.out.println("username " +username );
> System.out.println("password " +password );
> registerDB();
> connectDB();
> }
>
> // Register Driver
> private void registerDB() {
> System.out.println("registerDB " );
> try {
> DriverManager.registerDriver(new
> oracle.jdbc.OracleDriver());
> System.out.println("registerDB done.");
> } catch (Exception e) {
> System.err.println("problems registering .");
> }
> }
>
> // Connect To Database
> private void connectDB() {
> System.out.println("connectDBURL." );
> try {
> conn = DriverManager.getConnection
> ("jdbc:oracle:oci8:@" + database,
> username,
> password);
> // Create a statement
> Statement stmt = conn.createStatement ();
> stmt = conn.createStatement();
> System.out.println("connectDB: Connection done. ");
> } catch (Exception e) {
> System.err.println("connectDB: problems connecting to
> database. ");
> }
> }
>
> public void main (String[] args) {
> JoltData converter = new JoltData ();
> }
> }

If you are testing your applet using appletviewer then there are few things that you can look into.

  1. Copy classesxxx.zip to the same directory where JoltData.html is located.
  2. Edit JoltData.html and add reference to classesxxx.zip if not already present. e.g., <APPLET CODE="JoltData.class" ARCHIVE="classesxxx.zip" ....
  3. You may want to use java thin jdbc driver instead of oci driver. This way you can test/run your applet on any machine without Oracle client install.
  4. If you use jdbc thin driver, you would need to add permission java.net.SocketPermission "hostname" "connect, resolve" in your .java.policy file. If you don't have this file in your home directory, then use policytool to create one.

Regards
/Rauf Sarwar Received on Sat May 17 2003 - 18:38:42 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US