<%@ 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"/>
<h2>使用事务创建物理表</h2>
<sql:transaction dataSource="${datasource}">
<sql:update var="newTable">
create table mytable (
nameid int primary key,
name varchar(80)
)
</sql:update>
</sql:transaction>
<p>完成:使用事务创建物理表</p>
<hr>
<h2>使用事务插入数据到表</h2>
<sql:transaction dataSource="${datasource}">
<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>
</sql:transaction>
<p>完成:使用事务插入数据到表</p>
<h2>使用事务显示数据</h2>
<sql:transaction dataSource="${datasource}">
<sql:query var="deejays">
SELECT * FROM mytable
</sql:query>
<table border="1">
<tr>
<c:forEach var="columnName" items="${deejays.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<c:forEach var="row" items="${deejays.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
</sql:transaction>
<p>完成:使用事务显示数据</p>
<sql:update var="newTable" dataSource="${datasource}">
drop table mytable
</sql:update>
</body>
</html>
9.jstl之SQL:transaction
最新推荐文章于 2012-08-14 10:35:34 发布