1

I use NetBeans 6.5.

When I try to run the following code:

package com.afrikbrain.numeroteur16;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 
*/

public class NumeroteurTest {

  public NumeroteurTest() {

  }

  public void doIt() throws ClassNotFoundException{
    try {

      Class.forName("oracle.jdbc.OracleDriver");
      Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","user","pwd");
      String newNUMERO = new Numeroteur16("MATCLI", connection).numeroter();
      System.out.println("NUMERO GENERE : "+newNUMERO.toString());
    }
    catch (SQLException ex) {
            Logger.getLogger(NumeroteurTest.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
    }
    catch (NumException ex) {
      System.out.println(ex.getMessage());
      ex.printStackTrace();
    }

  }

  public static void main(String[] args){
        try {
            new NumeroteurTest().doIt();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(NumeroteurTest.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Driver not found.");
        }
  }
}

I get this error:

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at com.afrikbrain.numeroteur16.NumeroteurTest.doIt(NumeroteurTest.java:27)
        at com.afrikbrain.numeroteur16.NumeroteurTest.main(NumeroteurTest.java:45)
Driver not found.

How do I solve this problem?

3 Answers 3

1

The problem: Java can't find the JDBC Driver Class.
Solution: Add the Oracle JDBC Driver to your classpath.
You can get it at http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

Start java with java -classpath ojdbc14.jar ... to include the downloaded jar in your classpath.

Sign up to request clarification or add additional context in comments.

1 Comment

1

Add ojdbc6.jar to the project libraries. First, create a new library (NetBeans):

  • NetBeans -> Tools -> Libraries -> New library (Use a descriptive name eg: OracleJDBC6.)
  • Click OK, then Add JAR/Folder.
  • Type %ORACLE_HOME%\jdbc\lib\ojdbc6.jar, then confirm. On my computer, ORACLE_HOME=c:\app\admin\product\11.2.0\dbhome_1.

Finally, add the library to the project: Right-click on Libraries, , select Add library and select the library previously added.

Comments

0

Make sure that the Oracle driver is in the classpath. The thin driver is in ojdbc14.jar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.