无法连接到JDBC:需要CLIENT-PLUGIN_AUTH

时间:2019-07-02 08:07:52

标签: java mysql tomcat servlets jdbc

无法在Tomcat服务器中与MySQL建立JDBC连接。我一直在尝试其他方法,但无法解决错误。

我尝试了升级版本,还尝试了包含context.xml,我的数据库正在通过PHP连接,但是与Java一起,一次又一次地显示了这个问题,还为mysql连接器jar和referencerd环境变量设置了类路径:

boolean flag = false;
Connection con = null;
try
{
 Class.forName("com.mysql.cj.jdbc.Driver");
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mvc?user=user&password=password");

            String query = "insert into students (name,email,password) values(?,?,?)";
            PreparedStatement ps = con.prepareStatement(query);
}

这是我的服务器日志中的错误:

  

java.lang.ClassNotFoundException:com.mysql.cj.jdbc.Driver           在org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)           在org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)           在java.base / java.lang.Class.forName0(本地方法)           在java.base / java.lang.Class.forName(未知来源)           在models.Student.registerStudent(Student.java:32)           在controllers.RegisterServlet.doGet(RegisterServlet.java:54)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:634)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:741)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)           在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)           在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)           在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)           在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)           在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)           在org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)           在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)           在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)           在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:500)           在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)           在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:754)           在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1376)           在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)           在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(未知   资源)           在java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知   资源)           在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)           在java.base / java.lang.Thread.run(未知来源)

0 个答案:

没有答案