0% found this document useful (0 votes)
38 views

Java

The document contains Java servlet pages and servlets from 2018 to 2021 that connect to a MySQL database and display data in tables. The servlet pages use JDBC to connect to the database and execute SQL queries to retrieve data on politicians, smartphones, hospitals, patients, and smart lockdown areas. The data is displayed in HTML tables on the JSP pages. The servlets perform similar database queries and display the results in HTML sent to the response.

Uploaded by

Azaroath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Java

The document contains Java servlet pages and servlets from 2018 to 2021 that connect to a MySQL database and display data in tables. The servlet pages use JDBC to connect to the database and execute SQL queries to retrieve data on politicians, smartphones, hospitals, patients, and smart lockdown areas. The data is displayed in HTML tables on the JSP pages. The servlets perform similar database queries and display the results in HTML sent to the response.

Uploaded by

Azaroath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

2018.

Java Servlet Page


<%--
Document : p2018
Created on : Nov 14, 2022, 11:53:51 AM
Author : Ali
--%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JSP Page</title>
<style>
div{
display: flex;
justify-content: center;
}
table{
border-collapse: collapse;
}
th,td,tr,table{
border: 1px solid black;
padding: 10px;
}
</style>
</head>
<body>
<div>
<table>
<tr>
<th>Politician Name</th>
<th>Politician Current Party Name</th>
</tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from politician" );

while(rs.next()){
%>
<tr>
<td><%=rs.getString("pol_Name")%> </td>
<td><%=rs.getString("pol_Party")%> </td>
</tr>
<%}
}
catch(Exception e){
}
%>
</table>
</div>
</body>
</html>
2018. Servlet
package com.test;

import java.io.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
* @author Ali
*/
public class p20181 extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,


ServletException {
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<html><body>");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from item" );
out.print("<h1>Items</h1>");
out.println("<ol>");

while (rs.next() ){
String item = rs.getString("item_Name");
Number nitem = rs.getInt("no_of_items");
out.println("<li>" + item + "<b> Quantity: </b>" + nitem + "</li>");
}
out.println("</ol>");
out.println("</body></html>");
}
catch(Exception e){

}
}
}
2019. Java Servlet Page
<%--
Document : p2019
Created on : Nov 14, 2022, 7:30:43 PM
Author : Ali
--%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JSP Page</title>
</head>
<body>
<label> Choose a model: </label>
<select>
<option>Select</option>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from smartphone" );

while(rs.next()){
%>
<option><%= rs.getString("model") + " - " + rs.getString("company")%> </option>

<%}
}
catch(Exception e){
}
%>
</select>
</body>
</html>
2019. Servlet
package com.test;

import java.io.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
* @author Ali
*/
public class p20191 extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,


ServletException {
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<html><body>");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from country" );
out.print("<h1>Countries</h1>");
out.println("<ol>");

while (rs.next() ){
String item = rs.getString("name");
String nitem = rs.getString("capital_city");
out.println("<li>" + item + "<b> Capital: </b>" + nitem + "</li>");
}
out.println("</ol>");
out.println("</body></html>");
}
catch(Exception e){

}
}
}
2020. Java Servlet Page
<%--
Document : p2020
Created on : Nov 14, 2022, 8:27:28 PM
Author : Ali
--%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JSP Page</title>
</head>
<body>
<ul>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from corona1" );
while(rs.next()){
%>
<li><%=rs.getString("ward_incharge") + " / "
+rs.getString("hospital_name") + " , " + rs.getString("hospital_location")%> </li>
<%}
}
catch(Exception e){
}
%>
</ul>
</body>
</html>
2020. Servlet
package com.test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
* @author Ali
*/
public class p20201 extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,


ServletException {
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<html><body><table border=1 width=30%>");

out.println("<tr><th>Patient Name</th>");
out.println("<th>Patient CNIC</th>");
out.println("<th>Patient Location</th></tr>");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from corona" );

while (rs.next() ){
out.println("<tr><td>" + rs.getString("patient_name") + "</td>");
out.println("<td>" + rs.getString("patient_cnic") + "</td>");
out.println("<td>" + rs.getString("patient_location") + "</td></tr?");
}
}
catch(Exception e){

}
}
}
2021. Java Servlet Page
<%--
Document : p2021
Created on : Nov 14, 2022, 9:10:26 PM
Author : Ali
--%>
<%@page import="java.io.PipedWriter" %>
<%@page import="java.sql.*"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JSP Page</title>
<style>
div{
display: flex;
justify-content: center;
}
table{
border-collapse: collapse;
}
th,td,tr,table{
border: 1px solid black;
padding: 10px;
}
</style>
</head>
<body>
<div>
<table>
<tr>
<th>Area Name</th>
<th>City Name</th>
<th>No. of patients</th>
<th>No. of days</th>
</tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database?useSSL=false","root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery( "select * from smartlockdown" );

while(rs.next()){
%>
<tr>
<td><%=rs.getString("area_name")%> </td>
<td><%=rs.getString("city_name")%> </td>
<td><%=rs.getInt("no_of_patients")%> </td>
<td><%=rs.getInt("no_of_days")%> </td>
</tr>
<%}
}
catch(Exception e){
}
%>
</table>
</div>
</body>
</html>

You might also like