mysql - mysql 驱动程序错误 : javax. servlet.ServletException : java. lang.ClassNotFoundException : com. mysql.jdbc.Driver

标签 mysql eclipse apache jsp tomcat

我正在尝试向我的数据库中插入数据,但出现此错误:

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

这是我在数据库中插入数据的 jsp 文件。

插入.jsp

<%@page import = "java.io.*, java.sql.*, java.util.*"%>
<%@page import = "javax.servlet.http.*, javax.servlet.*"%>

<%
String name = request.getParameter("name");
String email = request.getParameter("email");
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");

String connectionURL = "jdbc:mysql://localhost:3306/dbmembers";
Connection connection = null;
PrepareStatament pstatement = null;
Class.forName("com.mysql.jdbc.Driver");

int updateQuery = 0;
if (name!=null && email!=null && uname!=null && pass!=null) {
    if (name!="" && email!="uname" && pass!="") {
        try{
            connection = DriverManager.getConnection(connectionURL, "root","");
            String queryString = "INSERT INFO tablemem (Name, Email, Uname, Pass) VALUES (?,?,?,?)";
            pstatememt = connection.preparedStatement (queryString);
            pstatement.setString(1, name);
            pstatement.setString(2, email);
            pstatement.setString(3, uname);
            pstatement.setString(4, pass);
            updateQuery = pstatement.executeUpdate();

            if (updateQuery != 0) { %>
                <table>
                    <tr>
                        <th>Successfully Registered</th>
                        <th><a href="login.jsp">Login here</a></th>
                    </tr>
                </table>
            <%
            }
        } catch (Exception ex) {
            out.println("Unable to connect to Database");
        }

        finally {
            pstatement.close();
            connection.close();
        }
    }
}
%>

我已经:

  • mysql-connector-java-5.1.39.jar 放在 WEB-INF/lib 中
  • 在eclipse中添加jar文件
  • 设置mysql的类路径

但我仍然遇到同样的错误。我错过了什么吗?

最佳答案

确保您已将连接器 jar 文件添加到构建路径中 为此,请右键单击 jar 文件并单击“添加到构建路径”

关于mysql - mysql 驱动程序错误 : javax. servlet.ServletException : java. lang.ClassNotFoundException : com. mysql.jdbc.Driver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540837/

相关文章:

eclipse - Eclipse 或 Aptana Studio 中是否有 "untab"(将代码块向左移动)的键盘快捷键?

Android 大量跳帧错误

apache - Opencart,OC 1.5.1.3,验证码错误

php - 立陶宛字符未正确保存到 MySQL 数据库中

mysql - 将 1 个参数与 mysql 中的多个字段进行比较

mysql - 如何根据不同的条件更新 MYSQL 列

mysql - 连接到 MySQL 数据库并计算行数

eclipse - Hive JDBC Web 应用程序中的 "Driver not capable"异常

Apache 在使用 mod_proxy 时忽略重写规则

apache - 如何找到我的 httpd.conf 文件?