簡體   English   中英

Servlet.service() for servlet [...] in context with path [/...] 拋出異常 [Servlet 執行拋出異常] 具有根本原因

[英]Servlet.service() for servlet [...] in context with path [/...] threw exception [Servlet execution threw an exception] with root cause

我正在嘗試設置數據源連接; 我實際得到的錯誤是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 驅動程序已過時,請檢查,您可以在此處查看更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM