gpt4 book ai didi

java - 找不到类异常 com.mysql.jdbc.driver

转载 作者:行者123 更新时间:2023-12-01 00:24:58 25 4
gpt4 key购买 nike

<分区>

我的项目的文件结构是:

         -src
|
-pkg
|
-CoreServlet.java(servlet)
-Main.java
-Core.java(jdbc code is here)

核心.java类:

package com.pkg;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class core{
private Connection connect = null;
private Statement statement =null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
String qwerty;

public void readDataBase() {
String userName = "ansh";
String password = "12345";
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/glbitm", userName,password);
statement = connect.createStatement();
resultSet = statement.executeQuery("select * from teachers");
resultSet.next();
qwerty = resultSet.getString(1);

} catch (Exception e) {
System.out.println(e);
}
}

}

coreServlet.java 类:

   package com.pkg;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class coreServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException{
core dao = new core();
dao.readDataBase();
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head><title>Hello World</title></head>");
pw.println("<div>"+dao.qwerty+"</div>");
pw.println("<body>");
pw.println("<h1>Hello World</h1>");
pw.println("</body></html>");
}
}

当我在 tomcat 服务器的 coreServlet.java 中访问 dao.qwerty 时。我收到 class not found exception com.mysql.jdbc.driver 并且 dao.qwerty 的值打印为 null。我哪里做错了?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com