0

I have seen many solutions in this site relating the same problem that I am facing now, I rectified my project structure also but still no success,

First attempt I placed mysqlconnector.jar in WEB-INF/lib -> GOT ERROR. Second, I removed it from lib folder, and added as external jar in build path -> GOT ERROR. Also I tried both above ways after placing mysqlconnector jar file in jre8/lib/ext -> NO SUCCESS!

Please ignore any small or irrelevant modifications, I just needed to check the connectivity thats all. I have JRE8 and Tomcat8 server running, which I believe is not an issue in this.

Here is a simple code of connectivity I just want to check if it is establishing a connection or not, that is why I haven't coded any further.

public class MySQLConnection {

    public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver"; 
    public static final String URL = "jdbc:mysql://localhost:3306/payinguest";
    public static final String USER = "root";
    public static final String PASSWORD = "root";


    public MySQLConnection() {
        try {
            Class.forName(DRIVER_CLASS);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
  }

My index.jsp is

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.pg.dao.MySQLConnection"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% MySQLConnection db = new MySQLConnection();%>
</body>
</html>

Error:

    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.pg.dao.JDBCMySQLConnection.<init>(JDBCMySQLConnection.java:15)
        at org.apache.jsp.index_jsp._jspService(index_jsp.java:71)

1 Answer 1

1

//Correction

 Use Jar file Instead of Zip in your class path.
Sign up to request clarification or add additional context in comments.

15 Comments

I just want to load/register the driver, rest i can connect it to database and further. My concern is it stops at line Class.forName(DRIVER_CLASS); which is simple statement.
i tried the steps you suggested, but still NO SUCCESS!
As you have mentioned earlier that you have placed jar file in lib, can you please add that jar file to build path as well and see if it works. Do this Project Properties > Java Build Path > Libraries > Add JARS and clean the project.
What about mysqlconnector version compatibility with jdk you are using!!
Yes, Why would you use zip file? It's obviously jar file.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.