0

Even though i have added the jar dependencies, it still shows the error when i deploy it in Chrome. When i enter username and password which is present in database, it fails to connect to database because of this exception. i have added mysqlconnector. I added it to file-> project structure-> modules-> dependencies and added over there. And also added to file-> project structure->libraries, by which it appeared in external libraries in hierarchy.

Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Exception report : See the Report Here

Tomcat log : Error lines

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

Validate class where DBconnection is defined

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class validate {

        public static boolean checkUser(String username, String password) throws ServletException {
            boolean st =false;



            try{

                //loading drivers for mysql
                Class.forName("com.mysql.jdbc.Driver");

                //creating connection with the database
                Connection con= DriverManager.getConnection
                        ("jdbc:mysql://localhost:8080/login","root","admin");
                PreparedStatement ps =con.prepareStatement
                        ("select * from log where username=? AND password = ?");
                ps.setString(1, username);
                ps.setString(2, password);
                ResultSet rs =ps.executeQuery();
                st = rs.next();

            }catch(Exception e)
            {
                throw new ServletException("Login failed", e);
            }
            return st;
        }
    }
Abhishek P
  • 95
  • 1
  • 9
  • what dependencies did you add? how did you add them? – Stultuske Feb 12 '18 at 11:07
  • mysqlconnector. I added it by file-> project structure-> modules-> dependencies and added over there. And also added to file-> project structure->libraries, by which it appeared in external libraries in hierarchy. – Abhishek P Feb 12 '18 at 11:09
  • and what is the exact error message? – Stultuske Feb 12 '18 at 11:10
  • It says java.lang.ClassNotFoundException: com.mysql.jdbc.Driver, you can see report above, i have embedded image just click on report. – Abhishek P Feb 12 '18 at 11:12
  • you could also have just added the text in the question itself, rather than posting a link to an image. Have you tried using maven or another dependency control system? – Stultuske Feb 12 '18 at 11:13
  • No i did not because i'm not familiar with those.. I usually use Eclipse but this time i choose Intellij but i'm facing problem. – Abhishek P Feb 12 '18 at 11:18
  • I'm not talking about an IDE. both Eclipse and IntelliJ have embedded versions of maven. it basically allows you to add the dependency with all it's specifications: library, version, scope, ... in a pom.xml file, and the build process will make sure that all relevant and necessary dependencies are correctly set – Stultuske Feb 12 '18 at 11:20

0 Answers0