<%@ 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:transaction dataSource="${datasource}">
<sql:update var="newTable">
create table mytable (
nameid int primary key,
name varchar(80)
)
</sql:update>
<h2>插入数据</h2>
<sql:update var="updateCount">
INSERT INTO mytable VALUES (1,'Paul Oakenfold')
INSERT INTO mytable VALUES (2,'Timo Maas')
INSERT INTO mytable VALUES (3,'Paul van Dyk')
</sql:update>
<p>完成:插入数据</p>
<sql:query var="deejays">
SELECT * FROM mytable
</sql:query>
</sql:transaction>
<table border="1">
<c:forEach var="columnName" items="${deejays.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
<c:forEach var="row" items="${deejays.rows}">
<tr>
<c:forEach var="column" items="${row}" varStatus="currentVarStaus">
<td><c:out value="${row[deejays.columnNames[currentVarStaus.index]]}"/> </td>
</c:forEach>
</tr>
</c:forEach>
</table>
<h2>删除第二行</h2>
<sql:update var="updateCount" dataSource="${datasource}">
DELETE FROM mytable WHERE nameid=2
</sql:update>
<p>完成:删除第二行</p>
<sql:query var="deejays" dataSource="${datasource}">
SELECT * FROM mytable
</sql:query>
<table border="1">
<c:forEach var="columnName" items="${deejays.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
<c:forEach var="row" items="${deejays.rows}">
<tr>
<c:forEach items="${row}" var="cuValue" varStatus= "currentVarStaus">
<td>
<c:out value="${row[deejays.columnNames[currentVarStaus.index]]}"/>
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
<sql:update var="newTable" dataSource="${datasource}">
drop table mytable
</sql:update>
</body>
</html>
10.jstl之SQL:delete
最新推荐文章于 2022-03-07 07:41:59 发布