gpt4 book ai didi

java - JDBC 领域找不到 mysql 驱动程序

转载 作者:行者123 更新时间:2023-11-28 22:47:44 24 4
gpt4 key购买 nike

我正在为我的动态 Web 项目使用 eclipse..

我的网站需要一个登录页面。我在 server.xml 中给出了以下配置:

<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/Chat?user=root&amp;password=public"
userTable="users" userNameCol="user_name" userCredCol="password" />

</Realm>

我已经在 java build path/libraries 中设置了 mysql-connector-java-8.0.12.jar

当我运行程序时,出现以下错误:

SEVERE: Exception opening database connection
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:644)
at org.apache.catalina.realm.JDBCRealm.startInternal(JDBCRealm.java:715)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:245)
at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:115)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:937)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:640)
... 19 more

但最终服务器启动了......当我尝试从登录页面登录时再次显示此错误......

MySQL版本为8.0.12

最佳答案

根据您所说的,您的类路径中似乎缺少 Mysql 驱动程序 jar。

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:640)

https://examples.javacodegeeks.com/java-basics/exceptions/java-lang-classnotfoundexception-how-to-solve-class-not-found-exception/

您可以尝试手动复制 <Webappdir>/web-inf/lib 中的 jar 吗? ?

关于java - JDBC 领域找不到 mysql 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52669982/

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