[tutorial] Database Connection in JSP with JSTL


I wrote the post about how to connect JSP applications and your Database, and in this post I’ll write the post that has same purpose but in the different way. we’ll connect the database via JSTL.

The project in this tutorial was made in the same project before, I just make another page in the same project.

In this tutorial I used the same database and table.

<%–
Document   : index
Created on : Oct 9, 2013, 11:40:46 AM
–%>
<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core&#8221; prefix=”c”%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql&#8221; prefix=”sql”%><!DOCTYPE html>
<html>
<head>
<title> </title>
</head>
<body><sql:setDataSource var=”snapshot” driver=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost/osis”
user=”root”  password=””/><sql:query dataSource=”${snapshot}” var=”result”>
SELECT * from pil;
</sql:query>

<table border=”1″ width=”100%”>
<tr>
<td>Kode </td>
<td>Nama</td>
<td>Count</td>
</tr>
<c:forEach var=”row” items=”${result.rows}”>
<tr>
<td><c:out value=”${row.kd}”/></td>
<td><c:out value=”${row.nama}”/></td>
<td><c:out value=”${row.count}”/></td>
</tr>
</c:forEach>
</table>

</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s