sql_update.jsp

来自「JavaWeb高级特性书中源代码」· JSP 代码 · 共 34 行

JSP
34
字号
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ page contentType="text/html;charset=gb2312" %>
<sql:setDataSource dataSource="jdbc/testSQL" var="myDataSource" />
<sql:update dataSource="${myDataSource}" var="myCreate">
	if object_id('student') is not null
		drop table student
	create table student(
		id int identity primary key,
		name varchar(10) not null,
		address varchar(80)
	)
</sql:update>
创建student表成功!<br />
<sql:update dataSource="${myDataSource}" var="myUpdate1">
	insert into student values('wangwu','Beijing')
	insert into student values('nation','Shanghai')
</sql:update>
向student表中添加记录数:${myUpdate1}<br />
<sql:update dataSource="${myDataSource}" var="myUpdate2">
	update student set address=? where name='wangwu'
	<sql:param value="${param.addr}" />
</sql:update>
更新记录的行数为:${myUpdate2}<br />
显示student表中的内容:
<sql:query var="student" dataSource="${myDataSource}" >
	select * from student
</sql:query>
<div style="text-align:center"><table border="1">
	<tr><td>name</td><td>address</td></tr>
	<c:forEach var="row" items="${student.rows}">
		<tr><td>${row.name}</td><td>${row.address}</td></tr>
	</c:forEach>
</table></div>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?