0

I am connecting to MySQL using JDBC to the JSP, but it shows error classNotFoundException in eclipse in struts JSP page.

validate.java:

package com.demo;
import java.sql.*;  
public class LoginValidate {

    public boolean validateLogin(){
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
        return true;    
    }
}

Same code using in same project jsp file its working what is problem i am not understanding.

index.jsp:

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p> There is home page.</p>
<hr/>  
<a href="login">login</a>|  
<a href="logout">logout</a>|  
<a href="profile">profile</a> 
<%

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
%>
</body>
</html>

I have included MySQL java connector on lib folder in eclipse struts project, but it is not working in action controller validate.java but it is working in index.jsp page.

What is problem? I could not understand.

3
  • What exception are you getting?
    – Saif Asif
    Jun 20, 2014 at 14:37
  • Add mysql jconnector jar in your project.
    – vivek
    Jul 1, 2014 at 8:04
  • check if u are not using eclipse, then add jar using build path . Jul 7, 2014 at 5:09

1 Answer 1

0

Its a pretty simple ClassNotFoundException. Make sure that the mySQL jar is present in the class-path of the project as well. You can do this by right-clicking the project, configure class-path and from there you can add the particular jar

2
  • please can you specify all step how to add classpath.I have added mysql jar inside web-info/lib directory and also java buildPAth->libraries.But still showing error classNotFoundException. Jun 21, 2014 at 8:34
  • build-path -> libraries is the actual method of adding a particular jar to the build path of the project. If you have done that and still you are getting the ClassNotFoundException then there is a possibility that the required classes are not in your class-path (other than mysql)
    – Saif Asif
    Jun 21, 2014 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.