简体   繁体   English

java.lang.ClassNotFoundException: com.mysql.jdbc.driver 错误,jar 文件已经导入

[英]java.lang.ClassNotFoundException: com.mysql.jdbc.driver error with jar file already imported

I have been searching all around for a solution to my problem and the only solution i have found is to add the jar file that i already have.我一直在四处寻找我的问题的解决方案,我找到的唯一解决方案是添加我已经拥有的 jar 文件。 This is done in eclipse EE and is useing tomcat.这是在 eclipse EE 中完成的,并且正在使用 tomcat。

I am running a different HTML file which links to this piece of code once a button is pressed, if you want that code feel free to ask, but there is almost nothing on it.我正在运行一个不同的 HTML 文件,一旦按下按钮,它就会链接到这段代码,如果您想要该代码,请随时询问,但几乎没有任何内容。

I keep getting the error "java.lang.ClassNotFoundException: com.mysql.jdbc.driver" along with 100 other lines which i'm not sure are conencted.我不断收到错误“java.lang.ClassNotFoundException:com.mysql.jdbc.driver”以及我不确定是否已连接的其他 100 行。

Here is what i have:这是我所拥有的:

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloForm
 */
@WebServlet("/test5")
public class test5 extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public test5() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub

        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "test";
        String driver = "com.mysql.jdbc.driver";
        String userName = "root";
        String password = "games10";

        try {
            Class.forName(driver).newInstance();
            Connection conn = (Connection) `enter code     here`DriverManager.getConnection(url+dbName,userName,password);

            Statement stat = conn.createStatement();
            //stat.execute("CREATE TABLE test (Name CHAR(20))");
            stat.execute("INSERT INTO TEST VALUES('"+request.getParameter("first_name")+"')");

            conn.close();
            System.out.println("Working");

        }

        catch (Exception e) {

            e.printStackTrace();

        }

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

I apolagize if i have posted the code wrong, ive never used this site before and am tired.如果我发布了错误的代码,我道歉,我以前从未使用过这个网站并且很累。 As i have said i have imported the "mysql-connector-java-5.1.30-bin.jar" file.正如我所说,我已经导入了“mysql-connector-java-5.1.30-bin.jar”文件。 All help is accepted with open arms and critisism also.张开双臂和批评也接受所有帮助。

Thank you for your time感谢您的时间

Errors in case it's not actually related to the driver:错误,以防它实际上与驱动程序无关:

java.lang.ClassNotFoundException: com.mysql.jdbc.driver at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at test5.doGet(test5.java:59) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(Standard java.lang.ClassNotFoundException: com.mysql.jdbc.driver at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) ) 在 java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at test5.doGet(test5.java:59) at javax.servlet.http.HttpServlet.service(HttpServlet.java) :620) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在 org.apache.catalina.core.ApplicationFilterChain。 doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org .apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在 org.apache.catalina.core.StandardWrapperValve.invoke(Standard WrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430) at java.util.concurrent.ThreadPo WrapperValve.java:220) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) 在 org.apache.catalina .core.StandardHostValve.invoke(StandardHostValve.java:170) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 在 org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:98) ) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 在 org.apache.coyote.http11.AbstractHttp11Processor。 process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430) 在 java.util.concurrent.ThreadPo olExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) olExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

导入 jar 后,您必须将其添加到项目的构建路径中。

right click on jar file -> build path ->add to build path

You've misspelt the class name, but you don't need it.您拼错了班级名称,但您不需要它。 Just remove that line.只需删除该行。 It's been obsolete for years, since JDBC 4.0.自 JDBC 4.0 以来,它已经过时多年。

I found the problem.我发现了问题。 I needed a uppercase D in String driver = "com.mysql.jdbc.driver";我需要一个大写的 D 在 String driver = "com.mysql.jdbc.driver";

God I feel stupid now上帝,我现在觉得自己很愚蠢

暂无
暂无

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

相关问题 错误:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver? - error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver? 错误:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Error : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver java.lang.ClassNotFoundException:com.mysql.jdbc.Driver(jar文件已经链接并放置在WEB-INF / lib中) - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver (jar file already linked and placed in WEB-INF/lib) Eclipse:我已经添加了JAR文件。 java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Eclipse: I have added the JAR file. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 通过命令行运行JAR时发生错误java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver while running JAR through Command line Runtime error while executing JAR file from CMD: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver - Runtime error while executing JAR file from CMD: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse Ubuntu中的java.lang.classnotfoundexception com.mysql.jdbc.driver - java.lang.classnotfoundexception com.mysql.jdbc.driver in ubuntu Maven java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Maven java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM