JDBC连接器 - Java EE - Eclipse Kepler - ClassNotFoundException

时间:2014-05-13 18:31:47

标签: eclipse jsp java-ee jdbc classnotfoundexception

我是Java Web Development的新手,最近我开始了一门课程,我有一个连接到MySQL数据库并显示它的任务。我有Eclipse Kepler和Java 7.55,作为服务器,我有GlassFish 4.0和MySQL 6.0.9。我已将jdbc连接器添加到项目(WEB-INF / lib)中,并且还具有连接到JRE系统库和Web应用程序库的连接器。

我有另一个使用文件上传制作的动态Web项目,在那里我能够添加上面提到的不同的外部jar文件,并且一切正常。 我为下面的问题做了同样的事,但我仍然收到错误。 我也尝试重新安装Eclipse和服务器以及MySQL jdbc连接器,但没有任何帮助。我删除了项目并重新构建它,但仍然没有。

jdbc连接器已添加到我想到的每个库中的任何位置。

我创建了一个新项目,以便能够连接到MySQL数据库

但是当我运行下面的代码(来自.jsp文件)时,我收到错误:

> HTTP Status 500 - Internal Server Error
> 
> --------------------------------------------------------------------------------
> 
> type Exception report
> 
> messageInternal Server Error
> 
> description The server encountered an internal error that prevented it from fulfilling this request.
> 
> exception 
> javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
> 
> root cause 
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
> 


And in the console I get this description:

*2014-05-13T21:12:13.195+0300|Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1761)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:187)
    at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:52)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    at java.lang.Thread.run(Thread.java:744)*

.jsp代码为:

<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% 
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", "emperor05");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page - Database Connection</title>
</head>
<body>
    <h2>Database Connection</h2>
</body>
</html>

很抱歉,如果是问题的重新发布,但我找不到合适的答案?

帮助?

提前谢谢。

1 个答案:

答案 0 :(得分:1)

尝试将该JAR放在Glassfish服务器/ lib而不是项目WEB-INF / lib中。也许Java EE类加载器需要更早地看到它来创建池。