Results 1 to 3 of 3
  1. #1
    Praveen Verma is offline Member
    Join Date
    Aug 2013
    Rep Power

    Default mysql eclipse classpath ubuntu problem

    Hi everyone, I am beginner in advanced java. I am using Ubuntu 12.04 LTS, mysql 5.5.32. I am trying to create a connection between mysql and servlet in JAVA EE eclipse .

    I have done some steps given below:

    a) added the mysql-connector-java-5.1.16.jar in the eclipse Project->Properties->Java Build path->Libraries->Add External JARs

    b) I have set the classpath in .bashrc file using command
    export CLASSPATH
    and then executed it using command
    source ~/.bashrc

    and then I have checked it using echo $CLASSPATH it displays

    Here are my servlet file :

    package com.student.servlet;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    * Servlet implementation class MySqlConnection
    public class MySqlConnection extends HttpServlet {
    private static final long serialVersionUID = 1L;

    * @see HttpServlet#HttpServlet()
    public MySqlConnection() {
    // TODO Auto-generated constructor stub

    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    out.println("Trying to load mysql driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("Select * from emp");
    out.println("ID " + rs.getInt(1));
    out.println("Name " + rs.getString(2));

    }catch (Exception e) {
    // TODO: handle exception

    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub


    Now I am getting the error in console of ECLIPSE

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at com.student.servlet.MySqlConnection.doGet(MySqlCon
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(

    I think, classpath is not set. So please suggest and help.

    Thanks in ADVANCE

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: mysql eclipse classpath ubuntu problem

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: mysql eclipse classpath ubuntu problem

    Quote Originally Posted by Praveen Verma View Post
    I think, classpath is not set. So please suggest and help.
    Tomcat manages the classpath. What you need to do is put the driver jar on the classpath according to the web application packaging rules described in numerous books, articles and in the Tomcat documentation. In this case, since you seem to be creating connections in your application if I believe the stacktrace.

    Application Developer's Guide (7.0.42) - Deployment

    How to properly package and deploy web applications from Eclipse is a whole different matter requiring completely different documentation. Plenty of resources on the net though, with pictures.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. java mysql ubuntu problem
    By maxxx12345 in forum JDBC
    Replies: 5
    Last Post: 12-06-2012, 04:23 PM
  2. Using mysql in Java on ubuntu
    By dearvivekkumar in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 11-30-2011, 10:36 AM
  3. eclipse shiro classpath problem...
    By kievari in forum Eclipse
    Replies: 4
    Last Post: 09-28-2011, 12:25 PM
  4. setting classpath for java in ubuntu
    By kulangotski in forum Java Servlet
    Replies: 0
    Last Post: 01-03-2011, 03:18 AM
  5. mysql classpath ubuntu problem
    By munish in forum JDBC
    Replies: 18
    Last Post: 08-22-2010, 01:55 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