[英]ClassNotFoundException when trying to connect with mysql dbms?
我在該站點上看到了許多解決方案,這些解決方案與我現在面臨的同一問題有關,我也糾正了我的項目結構,但仍然沒有成功,
第一次嘗試是將mysqlconnector.jar放在WEB-INF / lib-> GOT ERROR中。 其次 ,我從lib文件夾中將其刪除,並作為外部jar添加到構建路徑-> GOT ERROR中。 我也將mysqlconnector jar文件放在jre8 / lib / ext- > NO SUCCESS之后嘗試了以上兩種方法!
請忽略任何小的或不相關的修改,我只需要檢查所有連接即可。 我正在運行JRE8和Tomcat8服務器,我相信這不是問題。
這是一個簡單的連接代碼,我只想檢查它是否正在建立連接,這就是為什么我沒有進一步編碼的原因。
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();
}
}
}
我的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>
錯誤:
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.