wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes once again: classpath and ojdbc14.jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "once again: classpath and ojdbc14.jar" Watch "once again: classpath and ojdbc14.jar" New topic
Author

once again: classpath and ojdbc14.jar

Dirk Huth
Greenhorn

Joined: Apr 29, 2012
Posts: 6
Howdy folks,

I'm sure my question has been asked several times before, but I can't seem to find a fitting thread with the solution in this forum. Hope any of you has the patience to guide me through this.

I am "educating myself on technology", as it says on the respective IBM sites, so I downloaded a WebSphere Application Server v7 (base trial) and am experimenting with this now. I deployed a simple application which makes a connection to an Oracle Express DB (10g Express Edition Release 10.2.0.1.0) - that works, so I must have gotten something right. (Both the App-Server and the DB are running on localhost. For previous experiments I have changed Oracle's listener port to 1621 - in case anyone wonders.)

Now I am trying to test the oracle-connection with a stand-alone java-program I found on the net and I can't get the thing to acknowledge the driver: Where does this ojdbc14.jar go ???

Here's the program:



Thats my classpath:


And here is all the places where I dropped the driver:


The prog compiles alright, but when executed stops at line 15, even when I add the current directory to the classpath-option via


I keep getting "Exception: oracle.jdbc.OracleDriver" from the prog. I'm sure this is just some minor fault but I am absolutely stuck. Any help much appreciated, thanks in advance

Dirk

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

"home/dirk/myscripts/java/oracle_tests/ojdbc14.jar"


That path is a relative path, which means it's relative to your current working directory. So if your current working directory was (say) "/users/dirk", that path would represent

"/users/dirk/home/dirk/myscripts/java/oracle_tests/ojdbc14.jar"


But that wasn't what you said you meant. You said you meant

"/home/dirk/myscripts/java/oracle_tests/ojdbc14.jar"


So use that absolute path instead of the relative path which isn't right.
Dirk Huth
Greenhorn

Joined: Apr 29, 2012
Posts: 6
Hi Paul,

first of all - thanks for the quick reply! Unfortunately that didn't help. I'm on Ubuntu, so there is no directory /users/... There's just /home/... and e.g. /home/dirk

Anyway, it doesn't work.

Neither

javac -cp "/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib/ojdbc14.jar" OracleConnectionUrl.java

nor

javac -cp "/home/dirk/myscripts/java/oracle_tests/ojdbc.jar

Both get the same "Exception: oracle.jdbc.OracleDriver". So now I wonder is this the correct driver for Oracle Express DB (10g Express Edition Release 10.2.0.1.0)? (I guess it must be, because that's the driver I installed into the app-server and there it works.) Or am I using the "wrong" jdk? I have openjdk-6-jdk?

Hope we can finagle this out, best greetings,

Dirk
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Well for one thing, classpath aside, your code as shown will not get a Connection except on the first shot. If the first try throws an Exception all the other attempts to get the Connection will not be tried.


~Bill
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Unless you're using specific objects from the Oracle driver, you don't need to include the Oracle driver to compile your code. Also, have you tried Class.forName("oracle.jdbc.driver.OracleDriver"); instead?
Dirk Huth
Greenhorn

Joined: Apr 29, 2012
Posts: 6
@Bill: Yeah, but it's just a simple test. Since it is so basic it is supposed to work for all attempts without catching an exception.

@Koen: Yes I have - just now. The only thing that changes is the error-message:
Exception: oracle.jdbc.driver.OracleDriver

Also: compiling without explicitly invoking the path to the driver produces the same error.

I'm sure it's just a simple oversight somewhere but I can't get at it.

Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Provide a copy of the EXACT javac and java commands you're running, the paths from which you're running it, the resulting stacktrace/error message and the source of the java file you're trying to compile/run.
Dirk Huth
Greenhorn

Joined: Apr 29, 2012
Posts: 6
Hi Koen,

I'm afraid I don't quite see where you're getting at: The complete code is in my first post, as well as the javac-command I used. Below a copy of the things I'm trying, this time with the directory paths:


dirk@dirk-portable:~/myscripts/java/oracle_tests$ ls
HelloWorldApp.class HelloWorldApp.java ojdbc14.jar OracleConnectionUrl.class OracleConnectionUrl.java
dirk@dirk-portable:~/myscripts/java/oracle_tests$ javac -cp "/home/dirk/myscripts/java/oracle_tests/ojdbc14.jar" OracleConnectionUrl.java
dirk@dirk-portable:~/myscripts/java/oracle_tests$ java OracleConnectionUrl
Exception: oracle.jdbc.driver.OracleDriver
dirk@dirk-portable:~/myscripts/java/oracle_tests$


The Oracle-DB is running, I'm on a Linux VM (Ubuntu, lucid), I use openjdk 6, I changed the driver-definition both in the import statement and in the Class.forName statement according to your suggestion to oracle.jdbc.driver.OracleDriver.

Have you any suggestions as to what kind of trace I could try?

Thanks,

Dirk
Dirk Huth
Greenhorn

Joined: Apr 29, 2012
Posts: 6
Hi all,

it works now - although I'm not sure why. (As I said: absolute newbie.)

First I included the directory once more in the cp-argument:


(I saw that when working with a mySQL-example. I don't understand why this is necessary, though.)

got an error with the driver import so I commented it out

when I finally got to the "driver loaded ok" message I finagled it out with the help of google that the connection-string must include "user" and "password" as well, like


Best greetings,
Dirk
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: once again: classpath and ojdbc14.jar
 
Similar Threads
Java and ORACLE XE connectivity Problem
Tomcat 7 ClassNotFound Exception
connect oracle from java application
Classpath in JDBC
JSP-database problem