Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSP SQL Tag 
 

JSTL?s database library supports database queries and transactions.

 

JSP SQL Tag

                          

In this section you will learn how to use the jstl sql tag in jsp. 

JSTL’s database library supports database queries and transactions. JSP pages can import this library with the following directive:
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
You can see in the given example that in order to connect the jsp page to the database, we have used the jstl tag <sql:setDataSource> whose attributes are:
driver- Here you have to put the JDBC driver 
url- JDBC url for the database connection including database name
user-
the database username
password-
the database password

Understand with Example

The Tutorial illustrate an example from JSP SQL Tag. To understand the example we will show you to use jstl tag in jsp. The code consists of taglib directive that allow the jsp page to import  the library with the directive <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>. The example allow the jsp page to connect  to the database using <sql:setDataSource> specified with the given attribute. The attribute include name of the driver, url, user and password required to connect the database. The JSTL can read the data from the database using the tag <sql:query>. The code return the records from register table and print the corresponding values into your browser. 

c:out value="${}: The JSTL tag is used to print the fetched records from a table in the browser.

Here is the code of sql.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<sql:setDataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://
       localhost:3306/register" user="root" password="root"/>
<html>
<body>
<sql:query var = "user" >
Select user_id,firstName,lastName,userName,email from registerTable
</sql:query>

<table border=1>
<c:forEach var="row" items="${user.rows}">
<tr>
<td><c:out value="${row.user_id}"/></td>
<td><c:out value="${row.firstName}"/></td>
<td><c:out value="${row.lastName}"/></td>
<td><c:out value="${row.userName}"/></td>
<td><c:out value="${row.email}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>

Output will be displayed as:

Download Source Code:

                          

» View all related tutorials
Related Tags: c com orm table ant data join select form make tables tab for to between e ul result pe from

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.