JSP JSTL < SQL: update > tag: update data

Syntax:

The syntax of the query statement is as follows:



actions

The syntax of conditional query is as follows:


update statement optional

actions

Example 1

<%@page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
  <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
      <sql:setDataSource driver="com.MysqL.jdbc.Driver"
                         url="jdbc:MysqL://localhost:3306/db_testjstl"user="root"
                         password="111"/>
      <sql:update sql="INSERT INTO tb_user(username,pwd)VALUES('无语','111')"/>
      <table width="300" border="1" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF"
             bordercolordark="#999999" bordercolorlight="#FFFFFF">
        <tr>
          <td align="center">&nbsp;${rs.columnNames[0]}</td>
          <td align="center">&nbsp;${rs.columnNames[1]}</td>
          <td align="center">&nbsp;${rs.columnNames[2]}</td>
        </tr>
        <c:forEach items="${rs.rowsByIndex}" var="row">
          <tr>
            <td>&nbsp;${row[0]}</td>
            <td>&nbsp;${row[1]}</td>
            <td>&nbsp;${row[2]}</td>
          </tr>
        </c:forEach>
      </table>

Example 2

<%@page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
  <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    <sql:setDataSource driver="com.MysqL.jdbc.Driver"
                       url="jdbc:MysqL://localhost:3306/db_testjstl"user="root"
                       password="111"/>
    <sql:update sql="UPDATE tb_user SET pwd='123'WHERE username='无语'"/>
    <sql:query var="rs" sql="SELECT*FROM tb_user order by id desc"></sql:query>
<%@page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
  <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    <sql:setDataSource driver="com.MysqL.jdbc.Driver"
                       url="jdbc:MysqL://localhost:3306/db_testjstl"user="root"
                       password="111"/>
    <sql:update sql="UPDATE tb_user SET pwd='123'WHERE username='无语'"/>
    <sql:query var="rs" sql="SELECT*FROM tb_user order by id desc"></sql:query>

Example 3

<%@page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
  <%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
  <sql:setDataSource driver="com.MysqL.jdbc.Driver"
    url="jdbc:MysqL://localhost:3306/db_testjstl"user="root"
    password="111"/>
    <sql:update sql="DELETE FROM tb_user WHERE username='无语'"/>

Typical application

<%@page pageEncoding="gbk" contentType="text/html;charset=GBK"%>
  <%@taglib prefix="sql" uri="/WEB-INF/sql.tld"%>
    <%@taglib prefix="c" uri="/WEB-INF/c.tld"%>
      <sql:setDataSource driver="com.microsoft.jdbc.sqlserver.sqlServerDriver"
                         url="jdbc:microsoft:sqlserver://localhost:1433;databaseName=db_JSDQ26"
                         user="sa"password=""/>
      <%
         request.setAttribute("id",System.currentTimeMillis()%100);
         request.setAttribute("name",System.getProperty("os.name"));
         request.setAttribute("intro",System.getProperty("user.dir"));
         request.setAttribute("price",2000);
         request.setAttribute("NowPrice",1800);
       %>
        <sql:update
                    sql="insert tb_goods values(${id},'${name}','${intro}',${price},${NowPrice})"/>
        <sql:query var="result"
                   sql="select*from tb_goods where商品编号<=${id}order by商品编号desc"
                   maxRows="6"/>
        <table width="600" border="1" cellpadding="0" cellspacing="0"
               bordercolor="white" bordercolordark="white" bordercolorlight="black">
          <tr align="center" bgcolor="cyan">
            <td width="80">${result.columnNames[0]}</td>
            <td width="140">${result.columnNames[1]}</td>
            <td width="240">${result.columnNames[2]}</td>
            <td width="50">${result.columnNames[3]}</td>
            <td width="50">${result.columnNames[4]}</td>
          </tr>
          <c:forEach items="${result.rowsByIndex}" var="row">
            <tr>
              <td>${row[0]}</td>
              <td>${row[1]}</td>
              <td>${row[2]}</td>
              <td>${row[3]}</td>
              <td>${row[4]}</td>
            </tr>
          </c:forEach>
        </table>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>