File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes ClassNotFoundException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassNotFoundException" Watch "ClassNotFoundException" New topic
Author

ClassNotFoundException

Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
hi

I'm getting exception

java.lang.ClassNotFoundException racle.jdbc.driver.OracleDriver

What should i do, to resolve this problem..Where can i download classes12.jar and where should i paste it and in what form.

Please alse tell me whether i need to set any class path. Im using JDK1.4 and J2EE1.3, The back end is Oracle 9i.

Pls help me to solve this problem..


B.Swaminathan<br /> <br />Mobile:+91 09886510453
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The JDBC drivers are usually kept in %ORACLE_HOME%\ora91\jdbc\lib. You'll find it there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

you can get it from you installed oracle or downoad from here


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1124

B,
Please post the entire error message (and stack trace) you are getting, as well as the section of your code that is causing the error.

You mentioned J2EE, does this mean that some EJB is throwing this error?


Shailesh,
B has stated that he using Oracle 9i. You do realize that you gave him a link to Oracle 8i, don't you?


Paul,
Are you sure that B is on a Windows platform? I have Oracle 9i running on a SUN [sparc] with Solaris 9. I also have a ORACLE_HOME environment variable defined -- it points to directory:

And, as you say, the JDBC drivers are located in directory:

And that directory contains the file "classes12.jar" (among others).


B,
If you are new to Oracle JDBC, and assuming you haven't already found it, allow me to suggest the following Web page:

http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html

Good Luck,
Avi.

[ April 12, 2005: Message edited by: Avi Abrami ]
[ April 12, 2005: Message edited by: Avi Abrami ]
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
Hi

This is the error that J2EE gives me

Database Driver not found
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
java.lang.NullPointerException
Error Inserting the Data into the Table

The Code is

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;

public class LoginSAPOnline extends HttpServlet

{
Connection dbcon;

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
// Establishing Connection with database
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
dbcon=DriverManager.getConnection("jdbc racle:thin:@bbsu-2:1521:keonline","system","knowledge");
System.out.println("Connection Established");
}

catch(ClassNotFoundException e)
{
System.out.println("Database Driver not found");
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}

res.setContentType("text/html");
PrintWriter out=res.getWriter();
String username=req.getParameter("username");
String password=req.getParameter("password");
String previledge=req.getParameter("previledge");

int rows=0;
try

{
PreparedStatement s=dbcon.prepareStatement("insert into login_info(username,password,previledge) values (?,?,?)");
s.setString(1,username);
s.setString(2,password);
s.setString(3,previledge);
rows=s.executeUpdate();
}
catch(Exception e)
{
System.out.println(e.toString());
}
if(rows==0)
{
System.out.println("Error Inserting the Data into the Table");
System.out.println("Error insertting the data");
}
else
{
System.out.println("The values have been inserted into the table successfully");

}

}

}

Note:
Im working in Windows Environment using J2SDK1.4.2_04 and J2EESDK1.3.1

Thanks u so much for the efforts ur taking.
Today only i've registered in this forum and im very happy to say that all my doubts are getting cleared. People are doing a great job here!









Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1124

B,
So you are having trouble connecting to your database from your servlet, right? If you are using a servlet, then you must also be using a servlet engine (also known as a servlet container). Chances are that you need to configure the CLASSPATH used by your servlet engine -- so that it can find the "classes12.jar" file (or whatever JDBC driver you are using).

So maybe you can now tell us what servlet engine you are using, and then maybe someone will be able to tell you what to do so that your servlet can find your JDBC driver.

Good Luck,
Avi.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Based on your commments:
Im working in Windows Environment using J2SDK1.4.2_04 and J2EESDK1.3.1


It appears you are using sun's application server. I have not used it in awhile. So I can not tell you where to place the driver's jar file.

But, if you place the driver's jar file in the WEB-INF\lib directory, the web application should pick it up. Keep in my mind this is at the web application level.

If you want all applications to use the same drivers i.e. server/container level, you must place it in a directory specific to that server/container.

For example, if you were using TOMCAT's JSP/Servlet container, you will place the jar file in the %catalina_home%\common\lib folder.

I hope this helps.

Please correct me if I am wrong.
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
Hi friends,

The servlet Engine which i'm using is J2EE1.3.1, the Sun's application server where i deploy my servlet and other realted files.

Im a beginner,please correct me if i am wrong coz i believe Servlet engine is the server that includes built-in support for Servlets.

Cheers!
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
FYI, the new oracle 9i and 10i drivers for jdk 1.4 are packaged as ojdbc14.jar. Newer drivers that support jdk 1.2 are packaged as classes12.jar instead of the old classes12.zip.
[ April 12, 2005: Message edited by: Carol Enderlin ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
You are correct:
Im a beginner,please correct me if i am wrong coz i believe Servlet engine is the server that includes built-in support for Servlets.


But it does not not contain default support for all Vendor specific relational databases i.e. Oracle, MySQL etc.

You must place the files in a location where you application will have access to them at runtime(i.e WEB-INF\lib, CLASSPATH) and/or compile time.
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
hi,

I've downloaded ojdbc14.jar and pasted it in C:\j2sdk1.4.2_04\jre\lib. I've also set the Classpath to this location, but still i'l getting the same exception


Database Driver not found
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
java.lang.NullPointerException
Error Inserting the Data into the Table
Error insertting the data


The servlet code is



I did not get any error during compiling and deploying the servlet.

Please help me to solve this problem.

[edited to add code tags]
[ April 13, 2005: Message edited by: Jeanne Boyarsky ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Let's back up for a minute.

1. I am not familar with Oracle, first verify that the Class oracle.jdbc.driver.OracleDriver exists in the jar archive file ojdbc14.jar.

2. Since this is a servlet part of a web application, we need to make the ojdbc14.jar available to the any programs that are apart of the web application. Place the ojdbc14.jar in the WEB-INF/lib of the web application prior to re-deploying the web application to the J2EE application server.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1124

Craig,
I think you may be harboring a wrong assumption. You said:

Since this is a servlet part of a web application

Excuse me, but I couldn't see any mention, in B's posts, that he has a Web application. The only thing I can ascertain (from the information B has posted) is that he has a servlet that is trying to connect to a database, and that he is using SUN's application server. I suggest asking B to verify your assumptions, or you [both] may end up chasing your tails.

[Of-course, if you like chasing your tails, then don't let me stop you]

Good Luck,
Avi.
[ April 14, 2005: Message edited by: Avi Abrami ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405

Excuse me, but I couldn't see any mention, in B's posts, that he has a Web application. The only thing I can ascertain (from the information B has posted) is that he has a servlet that is trying to connect to a database, and that he is using SUN's application server. I suggest asking B to verify your assumptions, or you [both] may end up chasing your tails.


Actually, it hasn't gotten that far. The problem is that the application in question is unable find the Oracle Drivers to connect to the database. It just so happens that the application in question is a servlet. Based on the example code that was provided by Swaminathan
that generated the error messages:



Now I pulled this from the Servlet Specs

A servlet is Java Technology based web component, managed by a container, that generates dynamic content.
...
Containers, sometimes called servlet engines, are web server extensions that provide servlet functionality.

...
The web application classloader must load classes from the WEB-INF/ classes directory first, and then from library JARs in the WEB-INF/lib directory.


Now, I ask you Avi, if that is what you call an assumption, then so be it. I think I found my tail.

Thanks.
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
hi Avi,Craig

Let me feed you with more information..

The application, which i'm developing will be used by certain group of people..To be more clear i'm developing a Knowledge Base for the SAP Team in Organisation. This Knowledge Base Named as SAP Online should allow the users to post data and retrieve data from the server.

Actually the data are of large size and they are present within a folder in the Server.

The Scope of my application is that it should post(store) the data within a folder in the Server and retrieve the data based on the Search Key. This search process is similar to Google search i.e., Context Based Search.

Note: This application will be used by many client at same time.

The database is used to store the FileID,FileName,FileType,DateOfCreation,DateOfLastModification,KEYWORDS,
Path(The location of the file in the Server).

Now during the development stage, i have the Sun's Application Server J2EE1.3.1 and the Database installed in the Same system.

Pls help me in solving this problem, I've tried everything but still the application is not getting connected to the database i donno where i'm going wrong again and again.

Pls, Pls, Pls...Help me with a solution.

If u want more information pls let me know.
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
hi guys!

At last we have done it..

I've connected the Database with the application..

I made a copy of ojdbc12.jar and classes12.jar and once again pasted it in C:\JDKFOLDER\lib.

Now its Working..

Thank u friends, without ur help i would'nt have done this.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1124

Craig,

The web application classloader ...

I still call it an assumption, because prior to that reply, B had not said that he was using a Web application. So are you saying that a servlet must be part of a Web application? If so, then I guess your assumption is correct. However, I do know that there are servlet containers that allow you to create servlets that are not part of a Web application.

Obviously, in most cases your assumption would be correct, but since B had trouble in describing his situation (notice how I successfully coaxed the details out of him?), I thought that he may be in a very unorthodox situation. Hence the suggestion that you verify his situation -- because if your assumption was wrong, your answer may have just confused the two of you even more. You would have kept thinking that B was using a Web application (when in fact he wasn't) and B would have been trying (in vain) to implement your advice (with great difficulty, since he wasn't using a Web application).

But in future I will remember not to have the audacity to question the validity of your assumptions.

Good Luck,
Avi.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
First off, I would like to say congratulations B.Swaminathan. I knew it was
just a matter of time.


Secondly,

from Avi

because if your assumption was wrong, your answer may have just confused
the two of you even more

Actually, it seems it was you who may have been
confused. You made the following qoute:

posted April 12, 2005 06:37 AM Profile for Avi Abrami Send
New Private Message Edit/Delete Post Reply With Quote B,
So you are having trouble connecting to your database from your servlet,
right? If you are using a servlet, then you must also be using a servlet
engine (also known as a servlet container). Chances are that you need to
configure the CLASSPATH used by your servlet engine -- so that it can
find the "classes12.jar" file (or whatever JDBC driver you are using).

So maybe you can now tell us what servlet engine you are using, and then
maybe someone will be able to tell you what to do so that your servlet
can find your JDBC driver.


The above response from you was made after "B" stated the working
environment as:

Im working in Windows Environment using J2SDK1.4.2_04 and J2EESDK1.3.1


The servlet container is part of the J2EE application server.

Avi stated:
[QOUTE]So are you saying that a servlet must be part of a Web application? [/QOUTE]

Did I say that. I stated a servlet is part of a web application.

A web application may consist of servlets,
JSP pages, Utility classes, static documents(html, images, sounds, etc),
client side Java applets, beans, and classes, descriptive meta info which ties all together.

But what if any of this has to do with a servlet application unable to locate an archive library of vendor specific driver classes and helping B.Swaminathan move past this and move on.

Nothing.

And, because I knew like I am sure you knew that a servlet's life cycle is managed by a container and the web application classloader must load classes from the WEB-INF/classes directory first, and then from the library JARS in the WEB-INF/lib directory, so I suggested the following:


2. Since this is a servlet part of a web application, we need to make
the ojdbc14.jar available to the any programs that are apart of the web
application. Place the ojdbc14.jar in the WEB-INF/lib of the web
application prior to re-deploying the web application to the J2EE
application server.


The reason I suggested the WEB-INF/lib as 1 or 2 possible locations for the library jar files, is because I have not used the J2EE application server in awhile. Another possible suggestion was at the server/container level.

[QOUTE]
If you want all applications to use the same drivers i.e. server/container level, you must place it in a directory specific to that server/container.

For example, if you were using TOMCAT's JSP/Servlet container, you will place the jar file in the %catalina_home%\common\lib folder.
[/QOUTE]

And the reason, I suggested the WEB-INF\lib location over the server/container level, if he needed to deploy his "web component" in different servlet container or application server, the deployment would go alot smoother.

One more thing and I am done. Well two more things.
[QOUTE]You would have kept thinking that B was using a Web application (when in fact he wasn't) and B would have been trying (in vain) to implement your advice (with great difficulty, since he wasn't using a Web application).
[QOUTE]

If the JARs were placed in the WEB-INF\lib, in the same context as the servlet class, you and I wouldn't be having this conversation. Weellllll. maybe you would.

[QOUTE]
But in future I will remember not to have the audacity to question the validity of your assumptions. [/QOUTE]

I have no problem with that and that is not the point, but that is about all you have done, I was under the assumption(oops! sorry) we participate in this forum, because we want to help people like "B" solve problems, we have directly or indirectly experienced.

Sometimes, getting there is just as fun.
Swaminathan Balasubramani
Ranch Hand

Joined: Apr 12, 2005
Posts: 38
Thank you Craig!

Thank you so much..

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException