I know I'm beating a dead horse because everyone seems to have this problem and so have I in the past. Usually it is corrected by simply putting the correct .jar file in the classpath. Here is my code and classpath, if anyone can see an obvious problem I'm missing I would appreciate it.
Originally posted by Patrick Ferguson: I know I'm beating a dead horse because everyone seems to have this problem and so have I in the past. Usually it is corrected by simply putting the correct .jar file in the classpath. Here is my code and classpath, if anyone can see an obvious problem I'm missing I would appreciate it.
classes12.jar and classes12.zip - you should only have one, not both.
classes12.jar is pretty old stuff. the latest version is ojdbc14.jar.
are you trying to connect to oracle 10g? I think you'll need a newer driver.
I'm not crazy about your code. Why do you feel the need to embed the driver class that way? you're tied to oracle forever that way.
how are you running this example? is that CLASSPATH-like string an environment variable? I'd recommend not setting CLASSPATH that way. app servers and IDEs often ignore it completely. if you're using an IDE, you could be seduced into thinking that your CLASSPATH is all set because you have a system environment variable.
ClassNotFoundException means CLASSPATH to me. I'd revisit whether or not you really have that JAR in the CLASSPATH.
I might write that method this way to make it more general:
I prefer spelling out the parameters rather than passing in an array because it makes clear to clients what they need to provide and the proper order.
Joined: Jun 15, 2004
I appreciate your reply, but I'm not here for a coding lesson. This is basically a hello world type app while I try to get the oracle driver loaded. My real code is much different, but the point remains that it is failing when I try to load the oracle driver.
I have tried the classes12.jar in my path, as well as the ojdbc14.jar in my path. Each by themselves. I have probably tried 20 different classpath configurations, it's more like it can't read the driver out of the file. I checked file permissions on the .jar files and everything is open.
I am using an oracle 8i database.
I have not tried the process on UNIX yet (a place I have gotten similar applications to work), that's sort of a last resort.
Run your class from the command line with the -verbose flag. This will list all the classes the class loader loads. So, if your class is on the classpath you will see a "[Loaded oracle.jdbc.driver.OracleDriver from ....]" message. If you don't see the message there is something wrong with the classpath.
If you do, and you still can't load the class, then you have a very, very odd problem. [ October 17, 2005: Message edited by: Paul Sturrock ]
Well, the verbose output logs each class as it is loaded by a ClassLoader. ClassLoaders can only load resources which are in the classpath. So if there is no message, the class is not on the classpath.
You can double check this another way - write a quick program to load the class as a resource (i.e. with Class.getClassLoader().getResource("/oracle/jdbc/driver/OracleDriver.class") ;) . I the URL is null, the resource is not on the classpath (this has the extra bonus that if it isn't, the toString() method of URL logs the absolute path to the resource).
What do you do if the class still can't be found?
Double check the classpath is as you believe it to be - the output with -verbose will list the classpath too.
Check the integrity of the jar file you believe the class is in. (Long shot - perhaps you've managed to corrupt it in some way?)
Simplify things - write a program which you can run with only that jar in the classpath (the getResource example is a good candidate)
(javap: a new one to me - ah well, you learn something every day)
[ October 18, 2005: Message edited by: Paul Sturrock ] [ October 18, 2005: Message edited by: Paul Sturrock ]
I guess they must have refactored their package structure. Ah well, if nothing else an abject lesson in being careful what you put in your classpath, particularly if you end up putting a similar class in twice.
Joined: Jun 15, 2004
No, I used the proper one in the classpath, I typed the wrong one just now.
It's something very odd, and if it's a classpath issue I've never seen one like this.
Joined: Jun 15, 2004
Okay, after 3 days of fighting this I finally got it to work with this command.