在 Netbeans 默认安装的 Derby 示例数据库中使用 sql:query 和 CUSTOMER table

Using sql:query with CUSTOMER table in Derby's sample database in Netbeans default installation

我在 Windows 上使用 Netbeans 8.0.2。我写了一个例子JSP page

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Hello, World!</h2>
        <sql:query var="allRows" dataSource="jdbc/sample">
            SELECT name, city, state FROM APP.customer
        </sql:query>
        <table border="1">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Location</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach var="currentRow" items="${allRows.rows}">
                    <tr>
                        <td>"${currentRow.name}"</td>
                        <td>"${currentRow.city}", "${currentRow.state}"</td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </body>
</html>

但是如果我执行这个页面,我会得到

javax.servlet.ServletException: 
            SELECT name, city, state FROM APP.customer
        : Table/view 'APP.CUSTOMER' is not exist.

示例数据库是一个演示 Derby 数据库。我使用 GlassFish Server 4.1,JDK 7,Java EE 7。所有这些都在 Netbeans 的默认安装中。我使用 GlassFish Server 的默认设置。

我在“服务”选项卡上看到示例数据库连接。它是 jdbc:derby://localhost:1527/sample。我在 GlassFish 的 SamplePool 连接池属性中看到这个 url。此连接池用于 jdbc/sample JDBC 资源。 APP.CUSTOMER table 存在于示例数据库中。

我做错了什么?

我不确定哪里出了问题,但请尝试以下操作:

  • derbyclient.jarglassfish4/javadb/lib 复制到 glassfish4/glassfish/lib/endorsed
  • 重启 Glassfish
  • 将您的代码更改为以下内容:

    <sql:setDataSource var="snapshot" driver="org.apache.derby.jdbc.ClientDataSource"
                       url="jdbc:derby://localhost:1527/sample"
                       user="app"  password="app"/>
    <sql:query var="allRows" dataSource="${snapshot}">
        SELECT name, city, state FROM APP.customer
    </sql:query>
    

玩一个基本的例子这应该足够了,但你可能不想在生产中使用它。