<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
JSTL Update Tag provides capability to write insert, update or delete statements directly from JSP.</p>
<p> The <b><;sql:update>;</b> tag executes the provided SQL query through its body or through its sql attribute. Execution SQL queries using <;sql:update>; tag does not return any data. This tag can execute INSERT, UPDATE and DELETE statements.</p>
<p> Syntax-<br />
<i><;sql:update var=&#8221;<;string>;&#8221; scope=&#8221;<;string>;&#8221; sql=&#8221;<;string>;&#8221; dataSource=&#8221;<;string>;&#8221;/>;</i></p>
<p> <b>JSTL <i><;sql:Update>;</i> Tag has following attributes.</b></p>
<p> <b>1. datasource Attribute: </b>Specifies the datasource. Make sure that you already created datasource using serDataSource tag before writing query.</p>
<p> <b>2. sql Attribute: </b>Specifies the SQL statement to run on database.</p>
<p> <b>3. var Attribute:</b> Store the result of SQL statement.</p>
<p> <b>JSTL SQL UPDATE Tag Example:</b><br />
Now let us write a JSP which will make use of <b><i><;sql:update>;</i></b> to execute a SQL INSERT statement to create one record in the table as follows: </p>
<pre class="highlight" name="code"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>;
<;%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>;

<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
 "http://www.w3.org/TR/html4/loose.dtd">;
<;html>;
<;head>;
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">;
<;title>;JSTL SQL Tags - setDataSource Example<;/title>;
<;/head>;
<;body>;

 <;sql:setDataSource driver="com.mysql.jdbc.Driver"
 url="jdbc:mysql://localhost:3306/database_name"
 var="localSource" 
 user="database_user" 
 password="database_password"/>;
<;sql:update dataSource="${snapshot}" var="count">;
 INSERT INTO Employees VALUES (333, 27, 'Anamika', 'Rajput');
<;/sql:update>;
 <;sql:query dataSource="${localSource}" var="result">;
SELECT * from Employees;
<;/sql:query>;
 
<;table border="1" width="100%">;
<;tr>;
<;th>;Emp ID<;/th>;
<;th>;First Name<;/th>;
<;th>;Last Name<;/th>;
<;th>;Age<;/th>;
<;/tr>;
<;c:forEach var="row" items="${result.rows}">;
<;tr>;
<;td>;<;c:out value="${row.id}"/>;<;/td>;
<;td>;<;c:out value="${row.first}"/>;<;/td>;
<;td>;<;c:out value="${row.last}"/>;<;/td>;
<;td>;<;c:out value="${row.age}"/>;<;/td>;
<;/tr>;
<;/c:forEach>;
<;/table>;
<;/body>;
<;/html>;

</pre>
<p>
<b>Now try to access above JSP, which should display the following result:</b></p>
<table border="1" style="width: 100%px;">
<tbody>
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<tr>
<td>1111</td>
<td>Dinesh</td>
<td>Rajput</td>
<td>27</td>
</tr>
<tr>
<td>2222</td>
<td>Sweety</td>
<td>Rajput</td>
<td>23</td>
</tr>
<tr>
<td>3333</td>
<td>Anamika</td>
<td>Rajput</td>
<td>23</td>
</tr>
</tbody>
</table>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;">
<b><;<;<a href="https://dineshonjava.com/2013/10/jstl-sql-query-tag-example.html#.UmVyCBDpyxg">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/2013/10/jsp-standard-tag-library-jstl-tutorial.html">Index </a>||  ; >;>;<a href="https://dineshonjava.com/2013/10/jstl-sql-param-tag-example.html">Next</a> >;>;</b></div>
<p></div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jstl-sql-query-tag-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/jstl-sql-param-tag-example/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '296'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…