aspose file tools*
The moose likes JDBC and the fly likes problem in connecting to oracle through jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in connecting to oracle through jdbc" Watch "problem in connecting to oracle through jdbc" New topic
Author

problem in connecting to oracle through jdbc

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
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

Joined: Sep 16, 2002
Posts: 76
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

Joined: Mar 30, 2004
Posts: 84
I tried by placing class12.zip in lib (both in java and oracle diectories) but I am still getting the error.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the JDBC forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1132

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

Joined: Mar 30, 2004
Posts: 84
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

Joined: Oct 11, 2000
Posts: 1132

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

Joined: Aug 14, 2001
Posts: 342
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


SCJP 1.4, www.gsi3d.org.uk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in connecting to oracle through jdbc