随笔 - 26, 文章 - 0, 评论 - 2, 引用 - 0
数据加载中……

sql jdbc and jstl tag

basic

SELECT — used to query and display data from a database. The SELECT statement specifies which columns to include in the result set. The vast majority of the SQL commands used in applications are SELECT statements.
INSERT — adds new rows to a table. INSERT is used to populate a newly created table or to add a new row (or rows) to an already-existing table.
DELETE — removes a specified row or set of rows from a table
UPDATE — changes an existing value in a column or group of columns in a table


The more common DDL commands follow:

CREATE TABLE — creates a table with the column names the user provides. The user also needs to specify a type for the data in each column. Data types vary from one RDBMS to another, so a user might need to use metadata to establish the data types used by a particular database. CREATE TABLE is normally used less often than the data manipulation commands because a table is created only once, whereas adding or deleting rows or changing individual values generally occurs more frequently.

DROP TABLE — deletes all rows and removes the table definition from the database. A JDBC API implementation is required to support the DROP TABLE command as specified by SQL92, Transitional Level. However, support for the CASCADE and RESTRICT options of DROP TABLE is optional. In addition, the behavior of DROP TABLE is implementation-defined when there are views or integrity constraints defined that reference the table being dropped.

ALTER TABLE — adds or removes a column from a table. It also adds or drops table constraints and alters column attributes

jdbc

The following simple code fragment gives a simple example of these three steps:
++++ ConnectionSource.getConnection( "#","#","#"); ???? dbcp

Connection con = DriverManager.getConnection
( "jdbc:myDriver:wombat", "myLogin","myPassword");


Statement stmt = con.createStatement();
PreparedStatement pstmt=conn. prepareStatement(SQL);
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next()) {
int x = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c");
}


Jstl

<sql:update var="user" dataSource="${dataSource} " >
insert into tb_user (username,password) values (?,?)
<sql:param value="${param.username}" />
<sql:param value="${param[ password]}" />
</sql:update>
<c:redirect url="listUser.jsp">

< %@taglib url=" http://java.sun.com/jsp/jstl/core " prefix="c" %>
<
%@taglib url=" http://java.sun.com/jsp/jstl/fuction " prefix="fn"%>
<
%@taglib url=" http://java.sun.com/jsp/jstl/sql " prefix="sql"%>
<
%@taglib url="/struts-taglibs" prefix="s" %>


<sql:query var="rs" dataSource="${dataSoure}">
select * from tb_user
</sql:query>
<table >
<tr>
<th width=20%>#</th>
<th>#</th>
<th>#</th>
<th>#</th>
</tr>
<c:forEach var="user" item="${rs.rows}" >
<tr>
<td width=20%>${user.usename}</td>
<td>${user.password}</td>
<td><a href="editUser!input.jsp?id=${user.id}">编辑</a></td>
<td><a href="javascript:if(confirm('are you sure?'){document.location.href='deleteUserAction.jsp?id=${user.id}'};)">删除</a></td>
</tr>
</c:forEach>


1.core_Tags
<
%@taglib uri=" http://java.sun.com/jsp/jstl/core " prefix="c"%>
<c:set var="变量名" scope="page/session/request/application" value="值"/>
<c:set var="变量名" scope="page/session/request/application">值</c:set>
<c:remove var="变量名" scope="page/session/request/application"/>
<c:out value=${}/} 从小到大的范围查找变量
**********************************************************
<c:if test="${empty var}"></c:if>
**********************************************************
<c:choose>
<c:when test="${pageScope.var/session.var/...}"></c:when>
<c:when test="${}"></c:when>
<c:otherwise></c:otherwise>
</c:choose>
**********************************************************
<c:forEach items="包含要迭代的内容的数据结构对象 "
var="用户指定的当前正在迭代的元素"
varStatus="当前元素的状态(count|index|first|last)" count执行的次数,index索引值,first是否为第一个,last是否为最后一个
begin="迭代开始的位置 "
end="迭代结束的位置"
step="迭代的步长" >
</forEach>
**********************************************************eg:
<c:forTokens items="字符串" var="当前字符串" varStatus="" delims="定界符">
</c:forTokens>
**********************************************************
<c:import uri="" var=""/>
<c:url value="">
<c:param name="" value=""/>
</c:url>
<c:redirect url=""/>

2
.sql_Tags
<
%@taglib uri=" http://java.sun.com/jsp/jstl/core " prefix="sql"%>
连接
<sql:setDataSource var="" dirver="" url="" user="" password=""/>
操作
<sql:query dateSource="${}" var=" 结果集">select</sql:query>
<sql:update dateSource="${}">insert</sql:query>
<sql:update dateSource="${}">delete</sql:query>
事务
<sql:transaction dataSource="">
<sql:update var="">insert/update/delete</sql:update>
<sql:query var="">select</sql:query>
</sql:transaction>
显示
<c:forEach items="${结果集.rows}" var="记录" varStatus="s">
<h1 align="center">${s.count}|${ 记录 .dd}</h1>
</c:forEach>

posted on 2008-08-01 09:28 Anderson 阅读(202) 评论(0)  编辑  收藏 所属分类: java


只有注册用户登录后才能发表评论。


网站导航: