<sql:transaction dataSource="dataSource" isolation="isolation"> <sql:query .../> 或 <sql:update.../> </sql:transaction>其中:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ 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"%> <!DOCTYPE html> <html> <head> <title>编程帮(www.lmcjl.com)</title> </head> <body> <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8" user="root" password="root" /> <sql:transaction> <%-- 插入数据 --%> <sql:update dataSource="${snapshot}" var="result"> INSERT INTO website (NAME,url,age,country) VALUES ('京东', 'https://www.jd.com/', 15, 'CN'); </sql:update> <%-- 修改website表中id为8数据--%> <c:set var="id" value="8" /> <sql:update dataSource="${snapshot}" var="count"> UPDATE website SET name="biancheng" WHERE id = ? <sql:param value="${id}" /> </sql:update> <%-- 查询数据 --%> <sql:query dataSource="${snapshot}" var="result"> SELECT * from website; </sql:query> </sql:transaction> <table border="1" width="100%"> <tr> <th>id</th> <th>name</th> <th>url</th> <th>age</th> <th>country</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> <td><c:out value="${row.url}" /></td> <td><c:out value="${row.age}" /></td> <td><c:out value="${row.country}" /></td> </tr> </c:forEach> </table> </body> </html>
本文链接:http://task.lmcjl.com/news/18966.html