File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting exception in small JDBC Servlet Program.

 
PankajKumar jaiswal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the extension on your Oracle driver from '.zip' to '.jar', restart, and try again.
 
PankajKumar jaiswal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic