This tag used to execute the Select Statement in JSTL and stored value in variable.
This tag <sql:Query> used to implement or execute the select statement of sql Query. First we made a database named ‘dbase’ and table with required fields named ‘worker’ that will use to execute or linked with the front end. And all the drivers and attributes are also declared that will create a bridge between database and the coding as res. The query will fetch complete table in the program that will be presented on the web browser.
sqlQuery.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:query>Jstl Tag</title>
</head>
<body>
<sql:setDataSource var=”db” driver=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost/dbase” user=”root” password=”root”/>
<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>