• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in connecting to oracle through jdbc

 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
I am getting "Class Not Found" error while connecting to Oracle Database using JDBC connection.
I have written the following code....
import java.sql.* ;
import java.io.* ;
class CheckOra
{
public static void main(String args[])
{
Connection connection;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);

// Create a connection to the database
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "Homoeo";
String url = "jdbc racle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "lakshmi";
String password = "lakshmi";
connection = DriverManager.getConnection(url, username, password);
System.out.println("Connected");
} catch (ClassNotFoundException e) {
System.out.println("Class not found");
// Could not find the database driver
} catch (SQLException e) {
System.out.println("Could not connect");
// Could not connect to the database
}
}
}

Please tell me where I am going wrong.....
Thank u...
lakshmi
 
Padma Prasad
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you do not have oracle drivers for java. so, you get the error "class not found" for OracleDriver. Download classes12.zip from oracle site and put it in lib. This should work.
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried by placing class12.zip in lib (both in java and oracle diectories) but I am still getting the error.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JDBC forum...
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lakshmi,
The ClassNotFoundException is not (usually) due to a problem in your code, but in your environment. The JVM cannot find the JDBC driver classes. There are many ways to tell the JVM where to look for classes. The way I usually do it is via the "-classpath" option of the java command, example:

Alternatively, you may like to try the Extension Mechanism.
Good Luck,
Avi.
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried java -classpath "path to class12.zip;path to my java program" CheckOra
Still I am getting "Class not found"
How do I check I have all the ODBC/JDBC drivers/classes reqd in my system?
I have Oracle 8.1.6.0.0 on win 2000 server with sp1
Lakshmi
[ April 04, 2004: Message edited by: Sri Lakshmi ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lakshmi,
You can check the CLASSPATH using the following java code:

For what it's worth, I also unset the "ClassPath" environment variable before executing my java class, via the following command:

Good Luck,
Avi.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, I had this problem and couldn't figure it out. I ended up unpacking the package from the zip file into the lib directory and it started working
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic