隨筆 - 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 閱讀(207) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 龙井市| 普兰县| 彭州市| 兴化市| 乾安县| 年辖:市辖区| 东城区| 长汀县| 衡阳市| 萨嘎县| 乐都县| 新平| 前郭尔| 余姚市| 新乡市| 寿宁县| 东丰县| 广灵县| 嘉黎县| 汕头市| 乐平市| 印江| 鄄城县| 专栏| 宜城市| 临江市| 天等县| 万全县| 扶沟县| 巴楚县| 柘城县| 普洱| 梅河口市| 东兰县| 民勤县| 四子王旗| 平湖市| 监利县| 开平市| 洪湖市| 永兴县|