Intelij:我已经添加了所有依赖项,它仍然显示未找到jdbc驱动程序类的异常?

时间:2018-02-12 11:07:00

标签: java mysql servlets intellij-idea jdbc

即使我已经添加了jar依赖项,但当我在Chrome中部署它时仍会显示错误。当我输入数据库中存在的用户名和密码时,由于此异常,它无法连接到数据库。 我添加了mysqlconnector。我把它添加到文件 - >项目结构 - >模块 - >依赖关系并在那里添加。并且还添加到文件 - >项目结构 - >库,它出现在层次结构中的外部库中。

错误:java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

异常报告:See the Report Here

Tomcat日志:错误行

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

验证定义DBconnection的类

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class validate {

        public static boolean checkUser(String username, String password) throws ServletException {
            boolean st =false;



            try{

                //loading drivers for mysql
                Class.forName("com.mysql.jdbc.Driver");

                //creating connection with the database
                Connection con= DriverManager.getConnection
                        ("jdbc:mysql://localhost:8080/login","root","admin");
                PreparedStatement ps =con.prepareStatement
                        ("select * from log where username=? AND password = ?");
                ps.setString(1, username);
                ps.setString(2, password);
                ResultSet rs =ps.executeQuery();
                st = rs.next();

            }catch(Exception e)
            {
                throw new ServletException("Login failed", e);
            }
            return st;
        }
    }

0 个答案:

没有答案