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
  • That's not the right Driver name. That looks like a package/version name. Read the javadoc of the methods you use before using them. – Sotirios Delimanolis Jul 24 '13 at 17:54
  • I'll elaborate if you tell me what `Class.forName(String)` does. – Sotirios Delimanolis Jul 24 '13 at 17:56
  • it loads a class, statically – bigbitecode Jul 24 '13 at 17:57
  • 1
    Is there a class called `com.oracle.ojbdc6` anywhere on your classpath? Or rather `com.oracle.ojbdc6-11.2.0.1.0`? You must be looking for either `oracle.jdbc.driver.OracleDriver` or `oracle.jdbc.OracleDriver`. Those are your oracle jdbc driver classes (depending on the version). – Sotirios Delimanolis Jul 24 '13 at 17:58
  • http://stackoverflow.com/questions/8053095/what-is-the-actual-use-of-class-fornameoracle-jdbc-driver-oracledriver-while – Sotirios Delimanolis Jul 24 '13 at 17:59
  • The method doesn't seem to still find it. Perhaps I haven't made an actual classpath. However, via the picture I showed up there, I do have both those classes under maven – bigbitecode Jul 24 '13 at 18:08
  • What maven repo are you using? – Sotirios Delimanolis Jul 24 '13 at 18:30
  • The maven repository is where maven gets the jars for the dependencies you list. I can't find the one you listed in http://mvnrepository.com/. But your editor shows it as downloaded, so... – Sotirios Delimanolis Jul 24 '13 at 18:36
  • I didn't get it from a repo. I downloaded the driver from Oracle due to it being propietary. The pom.xml was changed after I loaded it via: mvn install:install-file -Dfile=G:\jdbc\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar || and I simply added: com.oracle ojdbc6 11.2.0.1.0 – bigbitecode Jul 24 '13 at 18:38
  • Maven should add it to your classpath by default. Search for how to add jars to classpath/buildpath on intellij (with and without maven). – Sotirios Delimanolis Jul 24 '13 at 18:40
  • For some reason the Maven hack I tried won't work. I tried adding jar manually and it worked. Thanks for the help Sotirios. – bigbitecode Jul 24 '13 at 19:17

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
  • 274,122
  • 60
  • 696
  • 724
  • 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
  • 857
  • 8
  • 19