Reputation:
I have installed Oracle 11.2 and Java:
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
In the command line, if i try to:
java oracle.jdbc.driver.OracleDriver
Java says: impossibile to load or find oracle.jdbc.driver.OracleDriver
I have copied ojdbc5.jar
, ojdbc6.jar
and ojdbc6_g.jar
From oraclexe\app\oracle\product\11.2.0\server\jdbc\lib
to
C:\Program Files\Java\jdk1.7.0_09\lib
If i run echo %CLASSPATH%
I get:
C:\Program Files\Java\jdk1.7.0_09\lib (ie where I have copied the jar files)
Any reasons why Java can't find oracle.jdbc.driver.OracleDriver
?
Upvotes: 2
Views: 99815
Reputation: 1
Before copying ojdbc6.jar
to <jdk-home>/jre/lib/ext/
, in IDEA you need to add the ojdbc6.jar
file in "Structure" -> "SDK" -> "add classpath" to <jdk-home>/jre/lib/ext/ojdbc6.jar
Upvotes: 0
Reputation: 1
I also had same problem and this is what i did I extracted ojdbc5.jar and then i copied oracle folder in extracted ojdbc5.jar and then pasted in current location where i wrote jdbc program ( not mentioning the directory as it differs from programmer to programmer), then used import oracle.jdbc.*; statement in my jdbc program as oracle.jdbc has OracleDriver in it. Rest of the program is same
Upvotes: 0
Reputation: 1503489
Putting a directory on the classpath doesn't put all the jar files within that directory on the classpath. It's not clear why you've copied the Oracle jar file into your Java installation directory - I'd recommend not doing that - but you should just list the location explicitly. For example, if you've copied it into the lib
directory relative to your application, you could use:
java -cp lib\ojdbc7.jar;. your.class.Name
You can use *
in a -cp
command line argument to find all jar files, e.g.
java -cp lib\*;. your.class.Name
or you could copy it into an "extensions" directory - but I think it's clearer to be explicit.
Upvotes: 1
Reputation: 109257
You reference a folder on the classpath and expect it to load all jars in it. That is not how the classpath works, you need to reference specific jars (and normally you should NOT put third party jars inside the JDK folder).
It is also important to know that the CLASSPATH
is usually ignored by java applications, except for the most basic use cases.
You can do what you try to achieve by doing:
java -cp <path-to>\ojdbc7.jar oracle.jdbc.OracleDriver
This will fail btw because OracleDriver
has no public static void main(String[] args)
method and therefor cannot be run like this. The normal way to use a JDBC driver is to have the driver on the application classpath, and simply specify the right driver URL. JDBC 4.0 (Java 6) or higher compliant drivers will be automatically loaded from the classpath (as specified with -cp
, the Class-Path
manifest entry etc).
On an unrelated note, oracle.jdbc.driver.OracleDriver
is considered deprecated, use oracle.jdbc.OracleDriver
instead, see Difference between Oracle jdbc driver classes?
Upvotes: 7