简体   繁体   English

尝试与mysql dbms连接时出现ClassNotFoundException?

[英]ClassNotFoundException when trying to connect with mysql dbms?

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. 第一次尝试是将mysqlconnector.jar放在WEB-INF / lib-> GOT ERROR中。 Second , I removed it from lib folder, and added as external jar in build path -> GOT ERROR. 其次 ,我从lib文件夹中将其删除,并作为外部jar添加到构建路径-> GOT ERROR中。 Also I tried both above ways after placing mysqlconnector jar file in jre8/lib/ext -> NO SUCCESS! 我也将mysqlconnector jar文件放在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. 我正在运行JRE8和Tomcat8服务器,我相信这不是问题。

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 我的index.jsp是

<%@ 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)

//更正

 Use Jar file Instead of Zip in your class path.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM