亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

ディレクトリ 検索
JSP 基礎(chǔ)教程 JSP 開發(fā)環(huán)境搭建 JSP 結(jié)構(gòu) JSP 生命周期 JSP 語法 JSP 指令 JSP 動(dòng)作元素 JSP 隱式對象 JSP 客戶端請求 JSP 服務(wù)器響應(yīng) JSP HTTP 狀態(tài)碼 JSP 表單處理 JSP 過濾器 JSP Cookies 處理 JSP Session JSP 文件上傳 JSP 日期處理 JSP 頁面重定向 JSP 點(diǎn)擊量統(tǒng)計(jì) JSP 自動(dòng)刷新 JSP 發(fā)送郵件 JSP 高級教程 JSP 標(biāo)準(zhǔn)標(biāo)簽庫(JSTL) <c:out> 標(biāo)簽 <c:set> 標(biāo)簽 <c:remove> 標(biāo)簽 <c:catch> 標(biāo)簽 <c:if> 標(biāo)簽 <c:choose> <c:import> 標(biāo)簽 <c:forEach> <c:param> 標(biāo)簽 <c:redirect> 標(biāo)簽 <fmt:formatNumber>標(biāo)簽 <fmt:parseNumber> 標(biāo)簽 <fmt:formatDate> 標(biāo)簽 <fmt:parseDate> 標(biāo)簽 <fmt:bundle> 標(biāo)簽 <fmt:setLocale> 標(biāo)簽 <fmt:setBundle> 標(biāo)簽 <fmt:timeZone> 標(biāo)簽 <fmt:setTimeZone> 標(biāo)簽 <fmt:message> 標(biāo)簽 <fmt:requestEncoding> 標(biāo)簽 <sql:setDataSource> 標(biāo)簽 <sql:query> 標(biāo)簽 <sql:update> 標(biāo)簽 <sql:param> 標(biāo)簽 <sql:dateParam> 標(biāo)簽 <sql:transaction> 標(biāo)簽 <x:out> 標(biāo)簽 <x:parse> 標(biāo)簽 <x:set> 標(biāo)簽 <x:if> 標(biāo)簽 <x:forEach> 標(biāo)簽 <x:choose> <x:transform> 標(biāo)簽 <x:param> 標(biāo)簽 fn:contains()函數(shù) fn:containsIgnoreCase()函數(shù) fn:endsWith()函數(shù) fn:escapeXml()函數(shù) fn:indexOf()函數(shù) fn:join()函數(shù) fn:length()函數(shù) fn:replace()函數(shù) fn:split()函數(shù) fn:startsWith()函數(shù) fn:substring()函數(shù) fn:substringAfter()函數(shù) fn:substringBefore()函數(shù) fn:toLowerCase()函數(shù) fn:toUpperCase()函數(shù) fn:trim()函數(shù) JSP 連接數(shù)據(jù)庫 JSP XML 數(shù)據(jù)處理 JSP JavaBean JSP 自定義標(biāo)簽 JSP 表達(dá)式語言 JSP 異常處理 JSP 調(diào)試 JSP 國際化
テキスト

<sql:query> 標(biāo)簽


<sql:query>標(biāo)簽用來運(yùn)行SQL SELECT語句,還有就是將結(jié)果存儲在作用域變量中。


屬性

<sql:query>標(biāo)簽有如下屬性:

屬性 描述 是否必要 默認(rèn)值
sql 需要執(zhí)行的SQL命令(返回一個(gè)ResultSet對象) Body
dataSource 所使用的數(shù)據(jù)庫連接(覆蓋默認(rèn)值) 默認(rèn)數(shù)據(jù)庫
maxRows 存儲在變量中的最大結(jié)果數(shù) 無窮大
startRow 開始記錄的結(jié)果的行數(shù) 0
var 代表數(shù)據(jù)庫的變量 默認(rèn)設(shè)置
scope var屬性的作用域 Page

程序示例

首先,需要在TEST數(shù)據(jù)庫中建一個(gè)Employees表,然后往表中添加幾條記錄,具體操作步驟如下:

步驟1:

打開CMD,將目錄轉(zhuǎn)至安裝目錄下:

C:\>
C:\>cd Program Files\MySQL\bin
C:\Program Files\MySQL\bin>

步驟2:

登陸數(shù)據(jù)庫:

C:\Program Files\MySQL\bin>mysql -u root -p
Enter password: ********
mysql>

步驟3:

在TEST數(shù)據(jù)庫中建立Employees表:

mysql> use TEST;
mysql> create table Employees
    (
     id int not null,
     age int not null,
     first varchar (255),
     last varchar (255)
    );
Query OK, 0 rows affected (0.08 sec)
mysql>

創(chuàng)建數(shù)據(jù)記錄:

最后,在Employees表中創(chuàng)建幾條記錄:

mysql> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
Query OK, 1 row affected (0.05 sec)
 
mysql> INSERT INTO Employees VALUES (101, 25, 'Mahnaz', 'Fatma');
Query OK, 1 row affected (0.00 sec)
 
mysql> INSERT INTO Employees VALUES (102, 30, 'Zaid', 'Khan');
Query OK, 1 row affected (0.00 sec)
 
mysql> INSERT INTO Employees VALUES (103, 28, 'Sumit', 'Mittal');
Query OK, 1 row affected (0.00 sec)
 
mysql>

現(xiàn)在,編寫JSP文件,使用<sql:query>標(biāo)簽來執(zhí)行SQL SELECT語句:

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<html>
<head>
<title>JSTL sql:query Tag</title>
</head>
<body>
 
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost/TEST"
     user="root"  password="pass123"/>

<sql:query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql:query>
 
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
<td><c:out value="${row.age}"/></td>
</tr>
</c:forEach>
</table>

</body>
</html>

運(yùn)行結(jié)果如下:

sql-source

關(guān)于我們 聯(lián)系我們 留言板

手冊網(wǎng)

前の記事: 次の記事: