This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes oracle db and java connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "oracle db and java connection" Watch "oracle db and java connection" New topic
Author

oracle db and java connection

Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

i m gettin no errors and no outputs,... wats the deal??

here's the code..


Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

You are hiding the exception. Change

to


I modified your post to use code tags for you to make it easier to read.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11447
    
  16

Now you know whey you should never swallow an exception:

An exception is thrown, you basically discard it, and throw it away. So you never know what happened...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at OracleExample.main(OracleExample.java:9)

Did the changes you told me. This is the error Im getting now. Totally confused. :/
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

though I have copied the oracle jar files in my classpath.. and made a DNS connection.. Im not getting an output..
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

The error means that the Oracle JDBC driver cannot be found on the classpath, so you've set the classpath incorrectly. How is your classpath set?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

I went to environment variables> system variables> classpath> .;C:\Programfiles\JAVA\jre7\lib\ext

I copied ojdbc14.jar and ojdbc14_g.jar here. Where did I went wrong?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

You'll have to put the JAR file itself in the classpath, not just the directory that contains the JAR file.
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

I tried still I am gettingg the same error. This is a runtime error. do I have to put the classpath in system variables or the user variables??
RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 64

Hi,
I too had same problem long back.That time i put the ojdbc14.jar inside server(eg: c:\program files\tomcat 6\lib) installed directory.
And the issue was resoved.Try this it might help.

Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

I'm doing this without using any IDE. I moved the file to jre7. Still I'm getting a runtime error




java.sql.SQLException: No suitable driver found for jdbc:oracle:thin: @localhost
:1522:hr
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at OracleExample.main(OracleExample.java:10)..
RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 64

hey check out this topic it might help..

webpage

webpage2
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

Using netbeans.. I'm getting following errors..

run:
Error: Could not find or load main class oracleexample.OracleExample
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 47

Add ojdbc14.jar to java build path of your project.
Thanks


Divya
SCJP1.6
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

did. doesnt work.

Java 7 , netbeans 1.7 , oracle 10g. any problem with that?
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 47

Try this may be it will work-

Create a new folder name 'lib' in your project inside WEB--->WEB-INF folder and copy the jar inside that lib folder.
Than clean and build your project in Netbeans and Run it.

Thanks


 
wood burning stoves
 
subject: oracle db and java connection