Solved

Connect Oracle Database To Java using JDBC

Posted on 2009-07-15
15
833 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

635 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