我在Windows上使用Netbeans 8.0.2。我写了一个示例JSP页面
<%@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表存在于示例数据库中。
我做错了什么?
答案 0 :(得分:3)
我不确定有什么问题,但请尝试以下方法:
glassfish4/javadb/lib
复制到glassfish4/glassfish/lib/endorsed
将您的代码更改为以下内容:
<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>
要使用基本示例,这应该足够了,但您可能不想在生产中使用它。