This Tag <sql:update> Execute The Sql statement like Insert,Update or Delete.
In This Program We Execute the Update Query to inserting a value in Connected Database. First we made a database named ‘dbase’ and Table with required fields named ‘worker’. Then after declaring the required variable we call The Drivers and Other attributes that are must for accessing the procedure to execute program and sql query. Here in last we produce the output on web browser in tabular form.
Sql:Update.jsp
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” prefix=”sql”%>
<html>
<head>
<title><sql:update>Jstl Tag</title>
</head>
<body>
<sql:setDataSource var=”db” driver=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost/dbase” user=”root” password=”root”/>
<sql:update dataSource=”${db}” var=”updt”>
INSERT INTO worker VALUES (‘Ashu’,’Area Manager’, 23, 18000);
</sql:update>
<sql:query var=”dt” dataSource=”${db}”>
select * from worker
</sql:query>
<table border=”1″>
<tr>
<td><b>Name</b></td>
<td><b>Job</b></td>
<td><b>Age</b></td>
<td><b>Salary</b></td>
</tr>
<c:forEach var=”values” items=”${dt.rows}”>
<tr>
<td>${values.name}</td>
<td>${values.job}</td>
<td>${values.age}</td>
<td>${values.salary}</td>
</tr>
</c:forEach>
</table>
</body>
</html>