我正在为动态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&password=public"
userTable="users" userNameCol="user_name" userCredCol="password" />
</Realm>
我已将mysql-connector-java-8.0.12.jar
设置为java build path/libraries
运行程序时,出现以下错误:
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
答案 0 :(得分:1)
按照您的意思,看来您在类路径中缺少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)
您可以尝试手动复制<Webappdir>/web-inf/lib
中的jar吗?