JSTL SQL Tag Lib

Posted on by By Somen Sarkar, in Big Data, Business Intelligence, Helical Insight, Miscellaneous | 0

The <sql:> tag lib in JSTL

The sql tag lib helps to develop a simple jsp database application. This taglib comes in handy with dataSoursetDataSource,  query, transaction and update tags

The tag lib can be used by putting the following in the jsp page.

<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” prefix=”sql”%>

The following syntax makes clear how to set the datasource.

<sql:setDataSource dataSource=”any database datasource”  />

<sql:setDataSource var=”datasourceName” driver=”driver class” url=”jdbc url here”  user=”username” password=”password”/>

The query tag can be used to query on the database and set the result set into (request, application, session) scope using the var attribute.

<sql:query var="result" 
select * from tablename where column=?"
<sql:param value="${bid}" />
</sql:query>

Note the usage of the param tag to set the parameters in the query.
The var tag stores the resultset and it corresponds to the Result interface
Using update tag can be used to update a database row.
The transaction tag is used to perform a series of SQL statements atomically.

<sql:transaction>
    ......
    ......
    ......
update statements using the update tag
    ......
</sql:transaction>

 

The <c:forEach> tag can be used to loop through the resultset and process the bussiness logic.

<c:forEach var="result" begin="0" items="${result.rows}">
.......your business logic.......

</c:forEach>

 

Thus we can use this feature in jsp to query some database and get the resultset.

 

 

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments