2

I'm getting the following error: ClassNotFoundException

java.lang.ClassNotFoundException: com.oracle.ojbdc6-11.2.0.1.0
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:186)
  at uk.ac.ebi.mydas.examples.Conn.main(Conn.java:23)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

On my intelliJ IDE I'm pretty sure I've set the dependencies properly on Maven: because on my External Libraries Folder, there's a "Maven: com.oracle:ojdbc6:11.2.0.1.0" package listed.

I'm assuming there's a problem with my code not being able address the class properly.

try {
    Class.forName("com.oracle.ojbdc6");
}

I realize that the jdbc drivers are not in the Maven repo, so I had to download it directly from the oracle website (correct version number) and load it to my library. I then added the pom.xml dependency successfully.

Maven: ojdbc dependency installed

Finally, here's my POM.xml:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.1.0</version>
    </dependency>

Thanks!

EDIT: Problem still occurs despite class OracleDriver being addressed. enter image description here

EDIT2: Here's a look into my module/dependencies setup on InnteliJ enter image description here

bigbitecode
  • 253
  • 5
  • 16

2 Answers2

1

The old (jdbc3) way of loading jdbc drivers was to load them with Class.forName(String). Each Driver probably had a static block that made them register themselves with the DriverManager.

The String you pass to Class.forName(String) is the fully qualified Class name of the Driver. Therefore, com.oracle.ojbdc6 and com.oracle.ojbdc6-11.2.0.1.0 are meaningless unless they are actual classes on your classpath.

Instead of com.oracle.ojbdc6 in

try {
    Class.forName("com.oracle.ojbdc6");
}

use either oracle.jdbc.driver.OracleDriver or oracle.jdbc.OracleDriver, which are both Driver classes. It depends on which version of the jdbc driver you are using.

Here's a related answer.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 263,859
  • 56
  • 671
  • 702
  • Thanks for bearing with me, Sotirios, I looked into the related answer and tried "java.lang.String" just to see if my string path was bad. Sure enough there's not complaint with the string class. I'm assuming this means I messed up with setting the classpath. How can I make sure I set it correctly? – bigbitecode Jul 24 '13 at 18:16
  • Your classpath is probably right. Just change the class name to what I put in my answer. If not, if intellij has some search function, try to find the class. If you can find it, it's probably on your project classpath. – Sotirios Delimanolis Jul 24 '13 at 18:22
0

shouldn't it be ojdbc6 instead of ojbdc6?

Filip
  • 847
  • 8
  • 19