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

Getting exception in small JDBC Servlet Program.

PankajKumar jaiswal
Greenhorn

Joined: Aug 13, 2006
Posts: 17
Hi,
I am using Tomcat5.0 and getting problem in a JDBC Program. What i did is;
1. Created a test folder in webapps (test is my project name.)
2. Created WEB-INF/classes folder and placed my small servlet class file which contains a small JDBC Program to database access.
3. Now i created another folder 'lib' in WEB-INF directory and placed classes111.zip inside it.
4. Created web.xml inside WEB-INF directory and other stuff.

The problem is that when i access my servlet it gives me following error message;
"java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver"
Looks like i have to make some editing in some config file so that jar/zip files in lib directory get loaded.
Please help. I have tried everything to resolve the problem. I even set CATALINA_HOME in environment variables and placed classes111.zip in common/lib directory so that it will be accessible to all the applications but this also didn't work.
My Servlet code is;

import java .sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{


String uid=req.getParameter("t1");

String pwd=req.getParameter("t2");

PrintWriter out=res.getWriter();
res.setContentType("text/html");

try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbcracle:thin:@localhost:1521racle8i", "scott", "tiger");
//Class.forName("oracle.jdbc.driver.OracleDriver");
//Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521racle8i","scott","tiger");
PreparedStatement psm=con.prepareStatement("select name,address from student where name=? and address=?");
psm.setString(1, uid);
psm.setString(2, pwd);
ResultSet rs=psm.executeQuery();
if(rs.next())
{
out.println("welcome "+uid);
}
else
{
out.print("sorry invalid "+uid);
}
rs.close();
psm.close();
con.close();

}
catch(Exception e)
{
out.println(e);
}
}
}

Thanks in Advance.....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Change the extension on your Oracle driver from '.zip' to '.jar', restart, and try again.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
PankajKumar jaiswal
Greenhorn

Joined: Aug 13, 2006
Posts: 17
Thanks dear.
It worked now. BTW, if this is the case can you tell me where we specify this thing... Just wanted to know so that i do not need to rename all the third party classes zip....
I am sure that it will be in some .bat file in bin folder. I tried to find it but got no success.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Tomcat loads its classes by looking for '.class' files in the classes directory and '.jar' classes in the lib directory.

I'm not sure why Oracle ships with a .zip extension and I don't remember where this is documented but I'm sure it is somewhere.
It's a common issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting exception in small JDBC Servlet Program.