NetBeans中使用DataSource連接Derby


  1. 登入Glassfish主控台,建立JDBC連線區(Connection Pool)

    點選新增後,會看到步驟一,這邊設定
    Connection Pool的名稱、資源類型及Database Vendor。這邊選擇內建的JavaDB做為範例。

    步驟二是Connection Pool的屬性設定,如果沒有特別需求,預設值就好


    最下方的屬性位置,填入相關資料,包括
    ServerNameDatabaseNameURL(URL需要手動增加)

    存檔離開。


  2. 建立JDBC資源,選擇剛剛建立的ConnectionPoolTest,存檔。

     

    Web Container的部分到此處設定完成,接下來設定web.xml

  3. 開啟web.xml,選擇Reference,到Resource Reference的地方新增

    Resource Name的地方要和Web Container上的相同(即設定成jdbc/sample2)

  4. 建立測試用的jsp檔案如下(使用JSTL)
    <%--
        Document   : jdbc_jstl
        Created on : 2008/11/6, 上午 01:02:39
        Author     : shen
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
      
       <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
       <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
       <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <sql:setDataSource dataSource="jdbc/sample2" />
            <sql:query var="result" >
                select NAME from APP.CUSTOMER
            </sql:query>
            <c:forEach items="${result.rows}" var="row" >
                ${row.NAME}<br>
            </c:forEach>
        </body>
    </html>

 

  1. 結果

 



arrow
arrow
    全站熱搜

    give 發表在 痞客邦 留言(0) 人氣()