Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 oraclexeapporacleproduct11.2.0serverjdbclib to
C:Program FilesJavajdk1.7.0_09lib

If i run echo %CLASSPATH% I get:

C:Program FilesJavajdk1.7.0_09lib (ie where I have copied the jar files)

Any reasons why Java can't find oracle.jdbc.driver.OracleDriver ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
591 views
Welcome To Ask or Share your Answers For Others

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...