Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2008, 10:54 AM
Member
 
Join Date: Jan 2008
Posts: 2
Rep Power: 0
surendra is on a distinguished road
Default Class not found Exception
I am using Eclipse 3.1 with tomcat5.5. I am building a dynamic web project,now i have a servlet which act as a controller and in its init() method i want to create connection to database, but classnotfoundException at line Class.forName("oracle.jdbc.driver.OracleDriver"); is thrown when i run this servlet.
I am confused where to put this driver class in my web application directory. or i have put jar file ..
my servlet code is given here.


package com.example.web;

import javax.servlet.http.*;
import javax.servlet.*;
import com.example.model.BeerExpert;
import java.io.*;
import java.sql.*;
import java.util.*;

public class BeerSelect extends HttpServlet {
Connection dbConnection;
public void init()
{
System.out.println(getServletName()+" : Initializing...");

Class.forName("oracle.jdbc.driver.OracleDriver");
// get a database connection
dbConnection = DriverManager.getConnection("jdbcracle:thin:@172 .28.21.25:1521:ram","s1","s1");
System.out.println("Initialized.");
}
//Creates connection in init() Retrieves parameters
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String c = request.getParameter("color");
// response.setContentType("text/html");
// PrintWriter pw =response.getWriter();
// pw.println("ffffffffffffff"+c);

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);

request.setAttribute("style", result);
RequestDispatcher rd = request.getRequestDispatcher("result.jsp");

rd.forward(request,response);

}

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 05:24 AM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 102
Rep Power: 0
wsaryada is on a distinguished road
Default
You can place you JDBC drivers jar file in the WEB-INF/lib folder of you web application. Placing any jar file inside this folder will make it available to you web application.
__________________
Website: Learn Java Programming by Examples - Blog: Java Programming Blog
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 12:33 PM
Member
 
Join Date: Jan 2008
Posts: 2
Rep Power: 0
surendra is on a distinguished road
Default
i already put that jar file under Web Content->WEB-INF->lib
but still it is not working.and give the exception:;;

java.lang.Error: Unresolved compilation problems:
Unhandled exception type ClassNotFoundException
Unhandled exception type SQLException

thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 06:45 PM
Member
 
Join Date: Jan 2008
Posts: 20
Rep Power: 0
maruthi_s is on a distinguished road
Default
Ok I don't think theres an issue with the jar file, its because the IDE which compiles your code expects the exception to be handled just add throws exception to your method and just start the server the issue will be resolved
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-11-2008, 07:23 AM
Member
 
Join Date: Jan 2008
Posts: 1
Rep Power: 0
srithota is on a distinguished road
Default solution to the JDBC Exception
Please put the statement Class.forName("oracle.jdbc.driver.OracleDriver"); within the try - catch statements and withing the catch, please catch the Exception... this should work.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 07:41 PM
404 Not Found mary Java Servlet 5 11-07-2007 11:15 AM
Exception Failed to Generate Wrapper Class on WebLogic christina New To Java 1 08-07-2007 03:15 AM
Error: no class definition found toby New To Java 4 07-27-2007 08:01 PM
java.lang.NoClassDefFoundError Exception when I invoke to a class outside projectEJB Daniel Enterprise JavaBeans 1 07-06-2007 07:08 AM


All times are GMT +2. The time now is 09:32 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org