Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2008, 10:54 AM
Member
 
Join Date: Jan 2008
Posts: 2
surendra is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 01-05-2008, 05:24 AM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 100
wsaryada is on a distinguished road
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:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 12:33 PM
Member
 
Join Date: Jan 2008
Posts: 2
surendra is on a distinguished road
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
maruthi_s is on a distinguished road
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
srithota is on a distinguished road
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
Sponsored Links
Reply


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

vB 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 +3. The time now is 09:36 PM.


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