【问题标题】:Servlet.service() for servlet [...] in context with path [/...] threw exception [Servlet execution threw an exception] with root causeServlet.service() for servlet [...] in context with path [/...] throw exception [Servlet execution throw an exception] with root cause
【发布时间】:2017-10-02 19:28:54
【问题描述】:

我正在尝试设置 DataSource 连接;我实际得到的错误是java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

但标题的错误会在上面弹出。

--

我有一个带有此 DataSource 设置的 caffeJdbc.java servlet

Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/caffeDB");
Connection con = dataSource.getConnection();

--

这是项目 web.xml 设置,带有 servlet 映射和资源引用

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>tjdbc</servlet-name>
    <servlet-class>caffeJdbc</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>tjdbc</servlet-name>
    <url-pattern>/caffeJdbc</url-pattern>
</servlet-mapping>

<resource-ref>
    <res-ref-name>jdbc/caffeDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

--

服务器.xml

<GlobalNamingResources>
 <Resource name="jdbc/caffeDB" 
 global="jdbc/caffeDB"
 url="jdbc:mysql://localhost:3306/caffe"/>
</GlobalNamingResources>

--

这是 context.xml

<Context path="/JDBCDataSource">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/caffeDB"
        name="jdbc/caffeDB"
        type="javax.sql.DataSource">
    </ResourceLink>
</Context>

我在 lib 目录和路径中加载了 JDBC 驱动程序和 commons-dbcp2-2.1.1 一个

【问题讨论】:

  • 可能是 JDBC 驱动程序过时了。看这个,stackoverflow.com/questions/32783706/…
  • 我以为这是最后一个发布的,但是,既然你告诉我,我查了一下,它是 2007 年的。如果你将这个作为答案重新发布,我很乐意支持它: )

标签: java servlets jdbc datasource


【解决方案1】:

可能是您使用的 JDBC 驱动程序已过时,请检查,您可以查看here 了解更多信息。

【讨论】:

    猜你喜欢
    • 2020-05-01
    • 2021-10-19
    • 2017-04-16
    • 2018-04-12
    • 2023-01-21
    • 2012-06-04
    • 2021-07-30
    • 1970-01-01
    • 2018-10-27
    相关资源
    最近更新 更多