Results 1 to 9 of 9
  1. #1
    surendra is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    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("jdbc:oracle: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);

    }

    }

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    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.

  3. #3
    surendra is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    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

  4. #4
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    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 :)

  5. #5
    srithota is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    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.

  6. #6
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default

    i too got the same problem, but i tried exporting the 'war' file to webapps folder of tomcat and re started the server. It worked fine for me.... i also did all the steps mentioned above... it worked for me somehow

  7. #7
    swapnalimore is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    when i run my code in eclipse i get the error that server encountered an internal error () that prevented it from fulfilling this request and http status error 404 also occurs. is there any problem in tomcat or mysql .Please reply asap. Thanks...

  8. #8
    swapnalimore is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    I am getting this error.....
    org.apache.jasper.JasperException: Exception in JSP: /LogIn/8June.jsp:15 12: String driver = "org.gjt.mm.mysql.Driver" 13: //String connectionURL = "jdbc:mysql://localhost:3306/test?user=root;password=root"; 14: 15: Class.forName(driver).newInstance(); 16: Connection con=null; 17: ResultSet rst=null; 18:
    Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:451) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:355) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet .java:729)

    root cause

    javax.servlet.ServletException: org.gjt.mm.mysql.Driver org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:841) org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:774) org.apache.jsp.LogIn.8Junejsp.jspService(8June_jsp .java:300) org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet .java:729) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet .java:729)

    root cause

    java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1386) org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1232) org.apache.jasper.servlet.JasperLoader.loadClass(J asperLoader.java:125) org.apache.jasper.servlet.JasperLoader.loadClass(J asperLoader.java:63) java.lang.Class.forName0(Native Method) java.lang.Class.forName(Unknown Source) org.apache.jsp.LogIn.8Junejsp.jspService(8June_jsp .java:60) org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet .java:729) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet .java:729)

  9. #9
    swapnalimore is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    String driver = "org.gjt.mm.mysql.Driver"; Class.forName(driver).newInstance(); //error at this line Connection con=null; ResultSet rst=null;

    Statement stmt=null;

    but this is the syntax for aceesing database in jsp

Similar Threads

  1. Replies: 2
    Last Post: 01-20-2014, 08:45 AM
  2. Error: no class definition found
    By toby in forum New To Java
    Replies: 6
    Last Post: 08-28-2011, 11:32 PM
  3. Replies: 1
    Last Post: 03-08-2008, 07:41 PM
  4. 404 Not Found
    By mary in forum Java Servlet
    Replies: 5
    Last Post: 11-07-2007, 11:15 AM
  5. Exception Failed to Generate Wrapper Class on WebLogic
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 03:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •