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” prefix=”c”%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” 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>
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” prefix=”c”%>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/sql” 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>