• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java program to Connect to database

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to write a simple java program to connect to Oracle database using Jrockit as my jvm.. Jrockit is being used by another 3rd party app (weblogic). I'm just using it to run my simple java program.

I'm new to java so following the steps provided here http://www.javacamp.org/moreclasses/jdbc/jdbc.html

The program gets compiled but I get the below error while running the program -

java.lang.classNotFoundException: 3Doracle.jdbc.driver.OracleDriver
JDBC Class found
SQL exception occured java.sql.SQLException: No suitable driver found for jdbc: oracle thin:@hostname:port:dbname

Please let me know the steps that need to be followed to make this connection work.



If I go to wlserver_10.3/server/ext/jdbc/oracle/11g..I can see the ojdbc5_g.jar,ojdbc5.jar,ojdbc6dms.jar, ojdbc6_g.jar, orai18n.jar, orai18n-mapping.jar files - which means the oracle driver is present.. but how do I use it ???

Thanks in Advance!
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That error typically means that Oracle driver isn't in your classpath. Try running the program as

On Windows:
java -cp "/path/to/Oracle/driver/oracleDriver.jar;." Uname

On UNIX/Linux/Mac:
java -cp "/path/to/Oracle/driver/oracleDriver.jar:." Uname
 
Kerin Kapoor
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply..

I've tried the below -
1. Compile - ./javac /app/utils/Uname.java

2. Run - ./java -cp "/app/wlserver_10.3/server/lib/ojdbc6.jar:." /app/utils/ Uname

But step 2 throws an error. I've tried the step2 without double quotes but no luck. The error is given below -

Exception in thread "Main Thread" java.lang.NoClassDefFoundError: /app/utils
Caused by : java.lang.ClassNotFoundException: .ap01.cap.hyperion.utils
at java.net. URLClassLoader$1.run(URLClassLoader.java.202)
at java.net. URLClassLoader.findClass(URLClassLoader.java.190)
at java.lang.ClassLoader.Loadclass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.LoadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: /app/utils/. Program will exit

Any pointers will be appreciated. I'm using Jrockit jvm installed with weblogic server...

Thanks in advance!!
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have two choices:

Option 1 - run from directory with code
cd into /app/utils
Run - ./java -cp "/app/wlserver_10.3/server/lib/ojdbc6.jar:." Uname

Option 2 - specify the directory the code is in
Run - ./java -cp "/app/wlserver_10.3/server/lib/ojdbc6.jar:/app/utils" Uname
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic