<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试JSTL</title>
</head>
<body>
<c:out value="测试JSTL"></c:out>
<sql:setDataSource var="datasource" dataSource="jdbc/sqlserver2008"/>
<sql:query sql="select top 10 * from tab_employees"
var="accountsRS" dataSource="${datasource}"/>
共查询出<c:out value="${accountsRS.rowCount}"/>条记录<br>
<table border="1" >
<tr>
<c:forEach items="${accountsRS.columnNames}" var="cucN">
<td>
<c:out value="${cucN}"/>
</td>
</c:forEach>
</tr>
<c:forEach items="${accountsRS.rows}" var="cuRe">
<tr>
<c:forEach items="${cuRe}" var="cuValue" varStatus= "currentVarStaus">
<td>
<c:out value="${cuRe[accountsRS.columnNames[currentVarStaus.index]]}"/>
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
<hr>
输出查询结果(使用rowsByIndex输出):
<table border="1" >
<tr>
<c:forEach items="${accountsRS.columnNames}" var="cucN">
<td>
<c:out value="${cucN}"/>
</td>
</c:forEach>
</tr>
<c:forEach items="${accountsRS.rowsByIndex}" var="cuRe">
<tr>
<c:forEach items="${cuRe}" var="cuValue">
<td>
<c:out value="${cuValue}"/>
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
</body>
</html>
4.jstl之SQL:query
最新推荐文章于 2024-05-11 16:43:25 发布