我正在尝试将已启用数据库的JSP添加到现有的Tomcat 5.5应用程序(GeoServer 2.0.0,如果有帮助的话).
该应用程序本身与Postgres谈话很好,所以我知道数据库已启动,用户可以访问它,所有这些好东西.我想要做的是在我添加的JSP中的数据库查询.我已经在Tomcat数据源示例中使用了配置示例,非常开箱即用.必要的taglibs位于正确的位置 - 如果我只有taglib refs就不会发生错误,因此它会找到那些JAR.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>
Run Code Online (Sandbox Code Playgroud)
来自$ CATALINA_HOME/conf/server.xml的相关部分,其内部<Host>依次是<Engine>:
<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>
Run Code Online (Sandbox Code Playgroud)
这些行是webapps/gs2/WEB-INF/web.xml中标记的最后一行:
<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>
Run Code Online (Sandbox Code Playgroud)
最后,例外:
exception
org.apache.jasper.JasperException: Unable …Run Code Online (Sandbox Code Playgroud) 哪种forName方法与registerDriver加载和注册JDBC驱动程序的区别?
我在这里读到,自从java 6以来你不再需要使用以下命令注册JDBC Driver:
Class.forName(JDBC_DRIVER);
Run Code Online (Sandbox Code Playgroud)
因为DriverManager使用位于系统属性"jdbc.drivers"中的路径 来检索正确的驱动程序.
但是当我做以下时:
System.out.print(System.getProperty("jdbc.drivers"));
Run Code Online (Sandbox Code Playgroud)
null 得到印刷.
你有什么线索为什么我的应用程序正常工作?;)