DATABSE CONNECTIVITY WITH JSTL-JSP (JAVA SERVER PAGES)
Postgres jar file is required
jstl.jar file is required
========================================================================
jstl sql tag demonstration........
<sql:setDataSource>
<sql:query>
<sql:update>
<sql:param>
<sql:dateParam>
<sql:transaction>
========================================================================
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<sql:setDataSource var="ds" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost:5433/java"
user="postgres" password="manager"/>
<%--retrieve all row from table in jstl jsp --%>
<sql:query dataSource="${ds}" var="result">
select * from user1234
</sql:query>
<table border="2" width="100%">
<tr>
<th>UserName</th>
<th>Phone</th>
<th>Emailid</th>
<th>Uid</th>
<th>Status</th>
</tr>
<h1>
<c:forEach items="${result.rows}" var="row">
<tr><td>${row.uname}</td><td>${row.phone}</td><td>${row.email}</td><td>${row.uid}</td><td>${row.status}</td></tr>
</c:forEach>
</h1>
</table>
<%--insert row into a table in jstl jsp --%>
<sql:update dataSource="${ds}" var="count">
insert into user1234 values('sushant','6767543433','sushant@gmail.com','78675su','y')
</sql:update>
<h1>The number of rows inserted:${count}<br></h1>
<%--delete row from table in jstl jsp --%>
<sql:update dataSource="${ds}" var="count">
delete from user1234 where uid='45698sa'
</sql:update>
<h1>The number of rows deleted:${count}<br></h1>
<%-- update row into a table in jstl jsp --%>
<sql:update dataSource="${ds}" var="count">
update user1234 set uname='manikumar' where uid='96969ma'
</sql:update>
<h1>The number of rows updated:${count}<br></h1>
<sql:update dataSource="${ds}" var="count">
update user1234 set uname=?where uid=?
<sql:param value="vikash"/>
<sql:param value="72345di"/>
</sql:update>
<h1>The number of rows updated:${count}<br></h1>
<sql:transaction dataSource="${ds}">
<sql:update>
update user1234 set uname='shanshay' where uid='9678hm';
</sql:update>
<sql:update>
update user1234 set uname='ragini' where uid='76545kp';
</sql:update>
</sql:transaction>
</body>
</html>
o/p view:-