JSP JSTL SQL标签操作数据库
来源:互联网 发布:java工作一年没提高 编辑:程序博客网 时间:2024/06/07 15:26
关于JSTL的标签信息可以查看《JSP JSTL标签》
直接上代码:
<%@ 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"%><% pageContext.setAttribute("testId", "123");%><!-- 设置数据源 --><sql:setDataSource var="dataSource" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:test" user="test" password="test" /><html><head><title>index</title></head><body> <p>查询数据</p> <sql:query var="result" dataSource="${dataSource}"> select id,name from table1 </sql:query> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th width="200">ID</th> <th width="200">Name</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> </tr> </c:forEach> </table> <hr /> <p>插入数据</p> <sql:update var="result" dataSource="${dataSource}"> insert into table1(id,name) values(?, 'testName') <sql:param value="${testId}" /> </sql:update> <p>影像记录条数:${result}</p> <sql:query var="result" dataSource="${dataSource}"> select id,name from table1 </sql:query> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th width="200">ID</th> <th width="200">Name</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> </tr> </c:forEach> </table> <hr /> <p>修改数据</p> <sql:update var="result" dataSource="${dataSource}"> update table1 set name = 'Name' where id = ? <sql:param value="${testId}" /> </sql:update> <p>影像记录条数:${result}</p> <sql:query var="result" dataSource="${dataSource}"> select id,name from table1 </sql:query> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th width="200">ID</th> <th width="200">Name</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> </tr> </c:forEach> </table> <hr /> <p>删除数据</p> <sql:update var="result" dataSource="${dataSource}"> delete from table1 where id = ? <sql:param value="${testId}" /> </sql:update> <p>影像记录条数:${result}</p> <sql:query var="result" dataSource="${dataSource}"> select id,name from table1 </sql:query> <table border="1" cellpadding="0" cellspacing="0"> <tr> <th width="200">ID</th> <th width="200">Name</th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}" /></td> <td><c:out value="${row.name}" /></td> </tr> </c:forEach> </table></body></html>
运行结果
0 0
- JSP JSTL SQL标签操作数据库
- JSP标签(JSTL)
- jsp---JSTL标签详解
- JSP JSTL fn标签
- JSP: JSTL标签详解
- jsp标签&jstl
- JSP:JSTL标签使用
- jsp标签库(jstl)
- JSP JSTL标签
- JSP JSTL标签用法
- JSP标签库JSTL
- JSP中的JSTL标签
- JSP之JSTl标签
- JSP 三 JSTL标签
- jsp--jstl标签使用
- jsp:jstl标签使用
- JSP交互---JSTL标签
- JSP标签JSTL的使用(1)--表达式操作
- FCKeditor上传漏洞总结
- Unity3D]结合轮廓显示,实现完整的框选目标
- Android安全攻防战,反编译与混淆技术完全解析(上)
- 软件开发技术:国际化(globalization )
- centos7 kvm网卡故障
- JSP JSTL SQL标签操作数据库
- 世界六大银行卡组织
- Android 获取充电状态
- 通过照相机拍照或者图库选择图片上传给服务器作为头像
- 文件解析漏洞总结
- Nmap Cheat Sheet Part 1
- iOS分类(Category)和类扩展(Extension)的简单区别
- 探知Java虚拟机——初识Java
- nmap学习笔记