Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

java - Cannot find or load oracle.jdbc.driver.OracleDriver

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

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

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...