wood burning stoves 2.0*
The moose likes JDBC and the fly likes java and oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java and oracle" Watch "java and oracle" New topic
Author

java and oracle

bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
i am expected to connect to database and for that purpose the following program is written.

import java.io.*;
import java.util.*;
import sun.jdbc.*;

public class Oracle_dbconnectivity {

public static void main(String[] args) {
new Oracle_dbconnectivity();
}

public Oracle_dbconnectivity(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Registered");

System.exit(0);

}
catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
System.exit(-1);
}
}
}


Output :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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Oracle_dbconnectivity.<init>(Oracle_dbconnectivity.java:21)
at Oracle_dbconnectivity.main(Oracle_dbconnectivity.java:16)

the version of oracle 8 is used . it is installed in E: drive.\\
"when i searched for the file java1java2 i found jdbc\odbc:" .
from file called jdbcodbc.dll which is present in E:\ORANT\BIN
but still the exception continues.

now do i connect to the database.


so how should i solve this problem.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
i forgot to mention that classpath variable is set to E:\ORANT\bin where jdbcodbc.dll is located.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
i am sorry but the file jdbcodbc.dll is located in E:\ORANT\JRE11\bin folder.
i set the classpath to E:\ORANT\JRE11\bin

still the problem continues even after adjusting the classpath.now how should i connect to the database?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why are you trying to connect to Oracle with the JDBC-ODBC driver? Unless you have a specific reason too, would you not be better using the type 4 driver supplied with Oracle?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
You need to add the oracle driver JAR file to your classpath, this is want is causing your problem, not the dll.

You can get the correct type 4 driver JAR file from the Oracle website.

Oracle Drivers

Regards
Jason
[ February 12, 2007: Message edited by: Jason Moors ]
Srikanth Basa
Ranch Hand

Joined: Jun 06, 2005
Posts: 241
Read the readme.txt under oracle\ora92\jdbc

You can see the jar files in oracle\ora92\jdbc\lib
[ February 12, 2007: Message edited by: Srikanth Basavaraju ]
Rao Raghu
Ranch Hand

Joined: Jan 05, 2007
Posts: 100
You did not import java.sql.*



RAGHU<br /> <br />"When the going gets tough, the tough get going"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by rao raghu:
You did not import java.sql.*



Thats OK. He's not using any classes from that package in his code, so no need to import it.
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
when i searched for jar files in my Oracle directory,i found these two jar files

1)i18n
2)rt

both of these are in E:\ORANT\JRE11\lib

i set the classpath as .;E:\jsdk2.1\servlet.jar;E:\jsdk2.1\server.jar;E:\ORANT\JRE11\lib\i18n.jar;E:\ORANT\JRE11\lib\rt.jar

when i ran the code the output is

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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Oracle_dbconnectivity.<init>(Oracle_dbconnectivity.java:21)
at Oracle_dbconnectivity.main(Oracle_dbconnectivity.java:16)
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
in our college we have installed Oracle 9i.
if that is the case classes12.zip must be included in the classpath as i found it from other sites


what should be the url arguement to getConnection() method.
DriverManager.getConnection(url,user_name,password);

Oracle has been installed in E drive.
E:\Oracle
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
please tell me about the URL component in getConnection method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java and oracle
 
Similar Threads
jdbc connection !!
Simple jdbc program error
MySQL DataBase
Unable to connect MYSQL :(
Why I can't run Web Start when my class using hibernate?