Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java and oracle

 
bhagavatula indu sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i forgot to mention that classpath variable is set to E:\ORANT\bin where jdbcodbc.dll is located.
 
bhagavatula indu sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not import java.sql.*

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me about the URL component in getConnection method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic