Java 在Netbeans默认安装中使用Derby示例数据库中的sql:query with CUSTOMER表
我在Windows上使用Netbeans 8.0.2。我编写了一个JSP页面示例Java 在Netbeans默认安装中使用Derby示例数据库中的sql:query with CUSTOMER表,java,netbeans,jdbc,glassfish,derby,Java,Netbeans,Jdbc,Glassfish,Derby,我在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"%> <!DOC
<%@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>
示例数据库是Derby的一个演示数据库。我使用GlassFish服务器4.1、JDK 7、JavaEE7。所有这些都在Netbeans的默认安装中。我使用GlassFish服务器的默认设置
我在“服务”选项卡上看到了示例数据库连接。它是jdbc:derby://localhost:1527/sample. 我在GlassFish的SamplePool连接池属性中看到了这个url。此连接池用于jdbc/示例jdbc资源中。示例数据库中存在APP.CUSTOMER表
我做错了什么?我不确定是什么错,但请尝试以下方法:
<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>
将derbyclient.jar从glassfish4/javadb/lib复制到glassfish4/glassfish/lib/annowed
重新启动玻璃鱼
将代码更改为以下内容:
<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>
要使用基本示例,这应该足够了,但您可能不想在生产中使用它。谢谢您的回答!它起作用了。现在我将尝试了解进一步定制GlassFish需要什么。