<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    Jstl 操作數據庫相關

    工作要找。。東西還是要學的。。。

    Code:
    JSTL SQL Query


    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>

    <sql:setDataSource?var="dataSource"?driver="org.gjt.mm.mysql.Driver"
    url="jdbc:mysql://localhost/forum?user=forumuser"
    scope="session"?/>

    <html>
    ??<head>
    ????<title>Query?Example</title>
    ??</head>

    ??<body>

    <sql:query?var?=?"users"?dataSource="${dataSource}">
    select?column_uid,column_pwd,column_accesses,column_first,column_last,column_bad,column_posted,column_type?from?t_users
    </sql:query>

    <table?border=1>
    <c:forEach?var="row"?items="${users.rows}">
    <tr>
    <td><c:out?value="${row.column_uid}"/></td>
    <td><c:out?value="${row.column_pwd}"/></td>
    <td><c:out?value="${row.column_accesses}"/></td>
    <td><c:out?value="${row.column_first}"/></td>
    <td><c:out?value="${row.column_last}"/></td>
    <td><c:out?value="${row.column_bad}"/></td>
    <td><c:out?value="${row.column_posted}"/></td>
    <td><c:out?value="${row.column_type}"/></td>
    </tr>
    </c:forEach>
    </table>


    ??</body>
    </html>

    JSTL SQL Update

    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/core-rt"?prefix="c-rt"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>

    <sql:setDataSource?var="dataSource"?driver="org.gjt.mm.mysql.Driver"
    url="jdbc:mysql://localhost/forum?user=forumuser"
    scope="session"?/>

    <html>
    ??<head>
    ????<title>General?Query</title>
    ??</head>

    ??<body>
    ??<c:choose>
    ????<c:when?test="${param.cmd!=null}">
    ??????<c:set?var="str"?value="${param.cmd}"?/>
    ????</c:when>

    ????<c:otherwise>
    ??????<c:set?var="str"
    ??????value="select?*?from?tableName"?/>
    ????</c:otherwise>
    ??</c:choose>

    ??Please?enter?a?query:
    ??<br?/>

    ??<form?method="post">
    ????<textarea?name="cmd"?cols="40"?rows="5">
    <c:out?value="${str}"?/>
    ????</textarea>

    ????<br?/>

    ????<input?type="submit"?/>
    ??</form>

    ??<c:if?test="${pageContext.request.method=='POST'}">
    ????<c:catch?var="e">
    ??????<sql:query?var="users"?dataSource="${dataSource}"
    ??????sql="${param.cmd}"?/>

    ??????<table?border="1">
    ????????<c:forEach?var="row"?items="${users.rows}"
    ????????varStatus="status">
    ??????????<jsp:useBean?id="status"
    ??????????type="javax.servlet.jsp.jstl.core.LoopTagStatus"?/>

    ??????????<c-rt:if?test="<%=status.getCount()==1%>">
    ????????????<tr>
    ??????????????<c:forEach?var="col"?items="${row}">
    ????????????????<th>
    ??????????????????<c:out?value="${col.key}"?/>
    ????????????????</th>
    ??????????????</c:forEach>
    ????????????</tr>
    ??????????</c-rt:if>

    ??????????<tr>
    ????????????<c:forEach?var="col"?items="${row}">
    ??????????????<td>
    ????????????????<c:out?value="${col.value}"?/>
    ??????????????</td>
    ????????????</c:forEach>
    ??????????</tr>
    ????????</c:forEach>
    ??????</table>
    ????</c:catch>

    ????<c:if?test="${e!=null}">
    ??????<h3>Error</h3>

    ??????<c:out?value="${e}"?/>
    ????</c:if>
    ??</c:if>
    ??</body>
    </html>

    Updating a database using the sql:update tag

    //web.xml

    <?xml?version="1.0"?encoding="UTF-8"?>
    <!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"
    ??"http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    ??<resource-ref>
    ????<res-ref-name>jdbc/address</res-ref-name>
    ????<res-type>javax.sql.DataSource</res-type>
    ????<res-auth>Container</res-auth>
    ??</resource-ref>
    </web-app>


    <%@?taglib?prefix="sql"?uri="http://java.sun.com/jstl/sql"?%>
    <%@?taglib?prefix="c"?uri="http://java.sun.com/jstl/core"?%>
    <html>
    <head>
    <title>Updating?a?database?using?the?sql:update?tag</title>
    <sql:setDataSource
    ??var="conn"
    ??dataSource="jdbc/address"
    />
    </head>
    <body>
    <h1>Modify?Address?List</h1>
    <sql:update?dataSource="${conn}"?var="addresses">
    ????INSERT?INTO?AddressList?(name,?street,?city,?country,?telephone)?VALUES?(?,??,??,??,??)
    ????<sql:param?value='${param["name"]}'/>
    ????<sql:param?value='${param["street"]}'/>
    ????<sql:param?value='${param["city"]}'/>
    ????<sql:param?value='${param["country"]}'/>
    ????<sql:param?value='${param["tel"]}'/>
    </sql:update>
    </body>
    </html>

    Presenting database content using tags

    //web.xml
    <?xml?version="1.0"?encoding="UTF-8"?>
    <!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"
    ??"http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    ??<resource-ref>
    ????<res-ref-name>jdbc/address</res-ref-name>
    ????<res-type>javax.sql.DataSource</res-type>
    ????<res-auth>Container</res-auth>
    ??</resource-ref>
    </web-app>




    <%@?taglib?prefix="sql"?uri="http://java.sun.com/jstl/sql"?%>
    <%@?taglib?prefix="c"?uri="http://java.sun.com/jstl/core"?%>
    <html>
    <head>
    <title>Presenting?database?content?using?tags</title>
    <sql:setDataSource
    ??dataSource="jdbc/address"
    ??var="conn"
    />
    </head>
    <body>

    <h1>Address?List</h1>
    <sql:query?dataSource="${conn}"?var="addresses">
    ????SELECT?*?FROM?AddressList
    </sql:query>
    <table?width="90%"?border="1">
    <tr>
    <!--?add?the?table?column?headings?-->
    <c:forEach?var="columnName"?items="${addresses.columnNames}">
    ??<th>?<c:out?value="${columnName}"/>?</th>
    </c:forEach>
    </tr>
    <!--?add?the?table?rows?from?the?result?set?-->
    <c:forEach?var="row"?items="${addresses.rowsByIndex}">
    ??<tr>
    ????<c:forEach?var="column"?items="${row}">
    ??????<td><c:out?value="${column}"/></td>
    ????</c:forEach>
    ??</tr>
    </c:forEach>
    </table>
    </body>
    </html>

    JSTL: Transaction with a JSP

    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>
    <html>
    <HEAD>
    ??????<TITLE>Using?a?Transaction?with?a?JSP</TITLE>
    ?????</HEAD>
    <body?bgcolor="white">
    ??????????<h2>View?table?Data</h2>
    <sql:transaction>??
    ??<sql:update>
    ??insert?into?atable?values(2,?'Joe','Id','Feb-24-1996','F')
    ??</sql:update>
    ????<sql:query?var="resultObj">
    ????select?*?from?atable
    ????</sql:query>

    </sql:transaction>??
    <table>
    <c:forEach?items="${resultObj.rows}"?var="row">
    ??<c:forEach?items="${row}"?var="column">
    ????<tr>
    ???<td?align="right">
    ?????<b><c:out?value="${column.key}"?/></b>
    ?????</td>
    ?????<td>
    ???????<c:out?value="${column.value}"?/>
    ?????</td></tr>
    ?????</c:forEach>
    ???????</c:forEach>
    ?????</table>
    </body>
    </html>



    SQL Tag Out Examples

    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>

    <sql:setDataSource?var="dataSource"?driver="sun.jdbc.odbc.JdbcOdbcDriver"?url="jdbc:odbc:forum"/>

    <html>
    ??<head>
    ????<title>SQL?Tag?Out?Examples</title>
    ??</head>

    ??<body>

    <sql:query?var?=?"users"?dataSource="${dataSource}">
    select?column_uid,column_pwd,column_accesses,column_first,column_last,column_bad,column_posted,column_type?from?t_users
    </sql:query>

    <table?border=1>
    <c:forEach?var="row"?items="${users.rows}">
    <tr>
    <td><c:out?value="${row.column_uid}"/></td>
    <td><c:out?value="${row.column_pwd}"/></td>
    <td><c:out?value="${row.column_accesses}"/></td>
    <td><c:out?value="${row.column_first}"/></td>
    <td><c:out?value="${row.column_last}"/></td>
    <td><c:out?value="${row.column_bad}"/></td>
    <td><c:out?value="${row.column_posted}"/></td>
    <td><c:out?value="${row.column_type}"/></td>
    </tr>
    </c:forEach>
    </table>


    ??</body>
    </html>

    詳細請看:http://www.java2s.com

    posted on 2006-06-15 19:27 record java and net 閱讀(1342) 評論(0)  編輯  收藏 所屬分類: Jsp&&Web

    導航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 又大又硬又爽又粗又快的视频免费| 永久中文字幕免费视频网站| 国产麻豆一精品一AV一免费 | 五月婷婷在线免费观看| 免费电影在线观看网站| 亚洲AV无码一区二区三区国产| 亚洲AV无码久久精品成人| 亚洲字幕AV一区二区三区四区| 福利免费在线观看| 日韩在线看片免费人成视频播放| 亚洲AV日韩AV天堂一区二区三区 | 亚洲日韩一中文字暮| 免费无码一区二区三区蜜桃 | 日韩免费视频播播| 国产精品亚洲lv粉色| 日本h在线精品免费观看| 亚洲天堂一区二区三区四区| 中国一级特黄高清免费的大片中国一级黄色片| 免费v片视频在线观看视频| 亚洲专区中文字幕| 免费成人高清在线视频| 久久久无码精品亚洲日韩蜜臀浪潮 | 免费的一级片网站| 瑟瑟网站免费网站入口| 国产日本一线在线观看免费| 久久久久亚洲AV成人无码网站| 99免费观看视频| 久久综合图区亚洲综合图区| 1000部禁片黄的免费看| 亚洲爆乳精品无码一区二区| 啦啦啦完整版免费视频在线观看| 亚洲六月丁香六月婷婷色伊人 | 久青草视频97国内免费影视| 亚洲成A人片在线观看中文| 国产免费播放一区二区| 久久久久久亚洲精品成人| 免费黄色毛片视频| 少妇性饥渴无码A区免费 | 亚洲a在线视频视频| 久久WWW免费人成人片| 又硬又粗又长又爽免费看 |