臭名昭著的java.sql.SQLException: No suitable driver found

128

我正在尝试将一个带有数据库功能的JSP添加到现有的Tomcat 5.5应用程序中(如果有帮助,应用名为GeoServer 2.0.0)。

该应用程序本身可以很好地访问Postgres数据库,所以我知道数据库是可用的,用户可以访问它,所有操作都正常。我正在尝试在我添加的JSP中进行数据库查询。我基本上直接使用了Tomcat datasource示例中的配置示例。必需的taglibs放置在正确的位置 - 如果只使用taglib引用,则不会出现任何错误,因此它能够找到这些JARs。Postgres JDBC驱动程序postgresql-8.4.701.jdbc3.jar位于$CATALINA_HOME/common/lib中。

以下是JSP的顶部:

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="jdbc/mmas">
  select current_validstart as ValidTime from runoff_forecast_valid_time
</sql:query>

$CATALINA_HOME/conf/server.xml 中的相关部分,位于 <Engine> 内的 <Host> 中:

<Context path="/gs2" allowLinking="true">
  <Resource name="jdbc/mmas" type="javax.sql.Datasource"
      auth="Container" driverClassName="org.postgresql.Driver"
      maxActive="100" maxIdle="30" maxWait="10000"
      username="mmas" password="very_secure_yess_precious!"
      url="jdbc:postgresql//localhost:5432/mmas" />
</Context>

这些行是在webapps/gs2/WEB-INF/web.xml文件的</taglib>标签中的最后一行:

<resource-ref>
  <description>
     The database resource for the MMAS PostGIS database
  </description>
  <res-ref-name>
     jdbc/mmas
  </res-ref-name>
  <res-type>
     javax.sql.DataSource
  </res-type>
  <res-auth>
     Container
  </res-auth>
</resource-ref>

最后,异常情况:

   exception
    org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    [...wads of ensuing goo elided]

请查看我的回答:https://dev59.com/XW035IYBdhLWcg3wNdPg#38656446 - Pacerier
22个回答

0
我遇到了相同的异常,但是在H2数据库上出现了,这是因为我在doFilter中对初始请求对象进行了操作。我这样做是因为我需要多次读取请求的Body,但是由于某种原因,它破坏了与H2控制台的连接。所以我做了以下操作,解决了这个问题:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    if (((HttpServletRequest) request).getRequestURI().startsWith("/h2-console/")) {
        chain.doFilter(request, response);
        return;
    }
    RepeatableHttpServletRequestWrapper wrappedRequest = new RepeatableHttpServletRequestWrapper((HttpServletRequest) request);
    chain.doFilter(wrappedRequest, response);
}

-2

我遇到了这个问题,是因为错误地将一个XML文件放入了src/main/resources中,我将其删除后,一切恢复正常。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接