<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>jstl-sql-tags &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/jstl-sql-tags/</link>
	<description>Feed of posts on WordPress.com tagged "jstl-sql-tags"</description>
	<pubDate>Sun, 26 May 2013 07:04:19 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[JSTL SQL Tags]]></title>
<link>http://softwareworker.wordpress.com/2011/12/10/jstl-sql-tags/</link>
<pubDate>Sat, 10 Dec 2011 04:01:00 +0000</pubDate>
<dc:creator>kiranbadi1991</dc:creator>
<guid>http://softwareworker.wordpress.com/2011/12/10/jstl-sql-tags/</guid>
<description><![CDATA[I came across this JSTL SQL Tags while trying to find the way for fixing the session problem where i]]></description>
<content:encoded><![CDATA[<p>I came across this JSTL SQL Tags while trying to find the way for fixing the session problem where in I was losing the session information for some reasons while displaying the result sets from servlets to JSP.JSTL tags were easy to learn and helped me in quickly bringing the page live.</p>
<p>JSTL SQL tags I believe is mostly related to interacting with database and provides a great interface from pulling the data out of database with minimal efforts.In case if you are in Netbeans its more of cakewalk,just pull and drop widgets from Netbeans palette and point it to the relevant data source.Database can be accessed both via JNDI Data source or by writing the connection strings in sql tags itself.We can just pull the data from the database and display it in with c out tag by iterating the result set. With SQL tags we can also set up the max result set size that can be retrieved in the database calls.</p>
<p>The first and foremost part to use JSTL tags is import JSTL tag library jars(Standard and JSTL.jars) and add it to the lib directory of the project and add the below line on the top of the page</p>
<pre class="csharpcode">&#60;%@ taglib uri=<span class="str">"http://java.sun.com/jsp/jstl/sql"</span> prefix=<span class="str">"sql"</span> %&#62;</pre>
<p>Below is sample code for SQL Tags to access database directly with sql setdatasource tag</p>
<pre class="csharpcode">&#60;sql:setDataSource var=<span class="str">"databasename"</span>
     url=<span class="str">"jdbc:mysql://localhost:3306/databasename"</span>
     driver=<span class="str">"com.mysql.jdbc.Driver"</span>
     user=<span class="str">"databaseuserid"</span> password=<span class="str">"databasepassword"</span>/&#62;</pre>
<p>In case if you have datasource defined in web xml file of the server, then its also quite easy to point the datasource with sql setDatasource tag,</p>
<pre class="csharpcode">&#60;sql:setDataSource  dataSource=<span class="str">"jdbc/databasename"</span>/&#62;</pre>
<p>Once you have datasource configured correctly, you can fire the query to fetch your results with c tags of JSTL tag library you can iterate and display the datasets in the page.</p>
<pre class="csharpcode">
&#60;sql:query var=<span class="str">"resultset"</span> scope=<span class="str">"page"</span>  maxRows=<span class="str">"100"</span>&#62;
   SELECT xx from tablename <span class="kwrd">where</span> xx == y orderby z Desc;
&#60;/sql:query &#62;</pre>
<p>maxRows attribute in the above sql query will be fetch the  number of rows of data what you require to display in the page.Scope is what you set for depending on your requirements.It could be be either session/page/application etc.Once you have result sets ,you can display it in the page and rest is all formatting the page container elements in the HTML Tags.</p>
<p>I would like to  say that most experts in java web world will not prefer to directly interact with database from the web page but again if you have a small applications with known set of users, then probably I feel its alright to access the database from the page.</p>
<p>In case if you are developing with Netbeans, then I feel it makes your job quite easy and fast.</p>
]]></content:encoded>
</item>

</channel>
</rss>
