Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Connect Oracle Database To Java using JDBC

Posted on 2009-07-15
15
Medium Priority
?
874 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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ā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

824 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