<!-- Simple program to demonstrate JSP and JDBC access -->
<!-- Form to submit Department name to JSP page in server -->
<!-- html forms -->
<html>
<head>
<title>HTML Forms, JSP and JDBC</title>
<style>
label
{
font-family:vivaldi;
font-size:x-large;
letter-spacing:2px;
line-height:40px;
}
</style>
</head>
<body>
<form method="GET" action="JSP_JDBC.jsp">
<center>
<h2>HTML Forms, JSP and JDBC</h2><br/>
<label>Enter Department Name </label>
<input type="text" Name="DN" tabindex=1/>
<br/> <br/>
<input type="submit" value="Get Code!!!"/>
</center>
</form>
</body>
</html>
<!-- JSP and JDBC -->
<html>
<body>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%@page import="java.sql.*"%>
<sql:setDataSource var="db" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@//localhost:1521/XEPDB1" user="system" password="Harini97#"/>
<sql:query dataSource="${db}" var="rs">
SELECT * from DC
</sql:query>
<center>
<h1> Department and Code </h1>
<table border="2" width="50%">
<tr>
<th>Department</th>
<th>Code</th>
</tr>
<c:forEach var="table" items="${rs.rows}">
<tr>
<td><c:out value="${table.name}"/></td>
<td><c:out value="${table.Code}"/></td>
</tr>
</c:forEach>
</table>
</center>
<%
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XEPDB1", "system", "Harini97#");
String dn = request.getParameter("DN").trim();
String qry = "SELECT * FROM DC WHERE name ='"+dn+"'";
PreparedStatement ps = conn.prepareStatement(qry);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
%>
<br/>
<center>
<h2>
Department Name : <%=rs.getString(1)%> <br/>
Department Code : <%=rs.getString(2)%>
</h2>
</center>
<%
}
%>
</body>
</html>
<!-- Form to submit Department name to JSP page in server -->
<!-- html forms -->
<html>
<head>
<title>HTML Forms, JSP and JDBC</title>
<style>
label
{
font-family:vivaldi;
font-size:x-large;
letter-spacing:2px;
line-height:40px;
}
</style>
</head>
<body>
<form method="GET" action="JSP_JDBC.jsp">
<center>
<h2>HTML Forms, JSP and JDBC</h2><br/>
<label>Enter Department Name </label>
<input type="text" Name="DN" tabindex=1/>
<br/> <br/>
<input type="submit" value="Get Code!!!"/>
</center>
</form>
</body>
</html>
<!-- JSP and JDBC -->
<html>
<body>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%@page import="java.sql.*"%>
<sql:setDataSource var="db" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@//localhost:1521/XEPDB1" user="system" password="Harini97#"/>
<sql:query dataSource="${db}" var="rs">
SELECT * from DC
</sql:query>
<center>
<h1> Department and Code </h1>
<table border="2" width="50%">
<tr>
<th>Department</th>
<th>Code</th>
</tr>
<c:forEach var="table" items="${rs.rows}">
<tr>
<td><c:out value="${table.name}"/></td>
<td><c:out value="${table.Code}"/></td>
</tr>
</c:forEach>
</table>
</center>
<%
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XEPDB1", "system", "Harini97#");
String dn = request.getParameter("DN").trim();
String qry = "SELECT * FROM DC WHERE name ='"+dn+"'";
PreparedStatement ps = conn.prepareStatement(qry);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
%>
<br/>
<center>
<h2>
Department Name : <%=rs.getString(1)%> <br/>
Department Code : <%=rs.getString(2)%>
</h2>
</center>
<%
}
%>
</body>
</html>
Thanks for posting such a Useful information.
ReplyDeletePython Online Training