Solved

Connect Oracle Database To Java using JDBC

Posted on 2009-07-15
15
787 Views
Last Modified: 2012-05-07
I want to set the environment for oracle to be connected to a java program,
First of all I want to set the ClassPath to "C:\oracle\product\10.2.0\db_2\jdbc\lib\classes12" in the environment variables. Right?, after testing it the result was:

C:\Users\Saed>java oracle.jdbc.driver.OracleDriver

Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/driver/Or
acleDriver
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: oracle.jdbc.driver.OracleDriver.  Program will ex
it.


what should the problem be ?
Thanks in advace

Saed Salman
0
Comment
Question by:SaedSalman
  • 4
  • 3
  • 3
  • +4
15 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24863628
I normally add ojdbc14.jar to my project.
0
 
LVL 6

Author Comment

by:SaedSalman
ID: 24863722
How, I am using TextPad,
0
 
LVL 6

Author Comment

by:SaedSalman
ID: 24863746
Also, I found out that "Oracle_Home" is not set to anything also...
I hope this helps
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 200 total points
ID: 24863792
Try adding the actual full path & filename to the JAR file to your CLASSPATH

Try running with

java -classpath C:\oracle\product\10.2.0\db_2\jdbc\lib\ojdbc14.jar
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 24864221
Try the following. Even if you had succeeded with your classpath in your command btw, you can't *run* a driver, so it wouldn't have worked
java -classpath C:\oracle\product\10.2.0\db_2\jdbc\lib\classes12.jar;. YourApp

Open in new window

0
 
LVL 7

Expert Comment

by:gudii9
ID: 24865047
ojdbc jar needs to be there and referenced in workspace
0
 
LVL 6

Author Comment

by:SaedSalman
ID: 24865105
Thank you all,
cehj, its work fine through command prompt, also I set the value of classpath to "C:\oracle\product\10.2.0\db_2\jdbc\lib\classes12.jar;" and run the program from Textpad and works fine... thank you

but what happened and what is the classpath and what does classes12.jar does ?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 92

Expert Comment

by:objects
ID: 24865289
Have a read here
http://mindprod.com/jgloss/classpath.html

calsses12.jar contains the oracle jdbc database driver needed to access oracle, so needs to be added to the classpath as mrjoltcola suggested above so it is available to your application
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24865316
>>what does classes12.jar does ?

classes12.jar is for older JDKs. Use odjbc14.jar for newer (JDK 4 and 5)
0
 
LVL 15

Expert Comment

by:fsze88
ID: 24865941
0
 
LVL 6

Assisted Solution

by:jwenting
jwenting earned 50 total points
ID: 24866832
as said, use modern drivers. The 12 in the archive name indicates the Java version it's compiled against, in this case 1.2.
Use the 1.4 or 1.5 drivers instead, which will also work with newer Oracle features and implement newer JDBC specs.

You don't want to ever use the system classpath. It's (as you noticed) not used by most applications.
Rather each application should set its own classpath to include only those libraries (and specific versions) it needs.
You can do that in a startup script for the application, and when running from an IDE there's always an option to specify the libraries that project needs.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24867448
>>cehj, its work fine through command prompt, also I set the value of classpath to "C:\oracle\product\10.2.0\db_2\jdbc\lib\classes12.jar;" and run the program from Textpad and works fine..

Good. If you do have the newer jars, that would be


java -classpath C:\oracle\product\10.2.0\db_2\jdbc\lib\ojdbc14.jar;. YourApp

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 24867483
as mrjoltcola already posted

> java -classpath C:\oracle\product\10.2.0\db_2\jdbc\lib\ojdbc14.jar
0
 
LVL 6

Author Closing Comment

by:SaedSalman
ID: 31603966
Thank you all, that was really useful
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24869637
>>cehj, its work fine through command prompt, also I set the value of classpath to "C:\oracle\product\10.2.0\db_2\jdbc\lib\classes12.jar;" and run the program from Textpad and works fine..

Good. If you do have the newer jars, that would be


java -classpath C:\oracle\product\10.2.0\db_2\jdbc\lib\ojdbc14.jar;. YourApp

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now