Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Connect Oracle Database To Java using JDBC

Posted on 2009-07-15
15
Medium Priority
?
849 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 800 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 1000 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 200 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup
Suggested Courses

722 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