Solved

Connect Oracle Database To Java using JDBC

Posted on 2009-07-15
15
798 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
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 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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
javap bin 2 34
Character matching different date formats for dates between 6 46
maven module vs maven project 3 23
What's wrong with this code? 4 23
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

770 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