Skip to content

Commit

Permalink
Simple Query
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Gedam15 committed May 4, 2022
1 parent e787656 commit 040091c
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 8 deletions.
1 change: 1 addition & 0 deletions build/classes/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/student_contact_info/
/student_info/
/uic_classes/
/vaccination_card/
Binary file modified build/classes/vaccination_card/dao/vaccination_cardDao.class
Binary file not shown.
Binary file not shown.
50 changes: 50 additions & 0 deletions src/main/java/student_contact_info/web/servlet/findAll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package student_contact_info.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import student_contact_info.service.student_contact_infoService;

/**
* Servlet implementation class findAll
*/

//public class extends HttpServlet {
// private static final long serialVersionUID = 1L;
//
// protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// doPost(request,response);
// }
//
// /**
// * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
// */
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// UserService userservice = new UserService();
// try {
// request.setAttribute("UserList", userservice.findall());
// } catch (InstantiationException | IllegalAccessException
// | ClassNotFoundException e) {
// e.printStackTrace();
// }
// try {
// List<Object> li = userservice.findall();
// for(int i = 0; i < li.size();i++){
// System.out.println(li.get(i).toString());
// }
//
// } catch (InstantiationException | IllegalAccessException
// | ClassNotFoundException e) {
// e.printStackTrace();
// }
//
//
// request.getRequestDispatcher("/jsps/user/q1_list_users.jsp").forward(request, response);
// }
//
//}
32 changes: 30 additions & 2 deletions src/main/java/vaccination_card/dao/vaccination_cardDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;



import user.domain.User;

//import java.util.ArrayList;
//import java.util.List;
Expand Down Expand Up @@ -133,4 +134,31 @@ public void delete(String UIN_p) throws ClassNotFoundException, InstantiationExc
throw new RuntimeException(e);
}
}


public List<Object> findDate() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
List<Object> list = new ArrayList<>();
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connect = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/uic_covid_database", MySQL_user, MySQL_password);
String sql = "select first_dose, second_dose from vaccination_card where Name = \"Vedant\"";
PreparedStatement preparestatement = connect.prepareStatement(sql);
ResultSet resultSet = preparestatement.executeQuery();
while(resultSet.next()){

vaccination_card user = new vaccination_card();
user.setFirst_dose( java.sql.Date.valueOf((resultSet.getString("first_dose"))) );
user.setSecond_date( java.sql.Date.valueOf((resultSet.getString("second_dose"))) );

list.add(user);
}
connect.close();
} catch(SQLException e) {
throw new RuntimeException(e);
}
return list;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* User object
*
* @author Aayush Makharia
* @author
*
*/
public class vaccination_card {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vaccination_card.service;


import java.util.List;

import vaccination_card.dao.vaccination_cardDao;
import vaccination_card.domain.vaccination_card;

Expand All @@ -25,4 +27,9 @@ public void create(vaccination_card form) throws vaccination_cardException, Clas
if(entity1.getUIN()!=null && entity1.getUIN().equals(form.getUIN())) throw new vaccination_cardException("This UIN has been registered!");
entity1Dao.add(form);
}

public List<Object> findDate() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
return entity1Dao.findDate();

}
}
40 changes: 40 additions & 0 deletions src/main/java/vaccination_card/web/servlet/displayDoseDate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package vaccination_card.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vaccination_card.service.vaccination_cardService;

/**
* Servlet implementation class findAll
*/

public class displayDoseDate extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
vaccination_cardService userservice = new vaccination_cardService();
try {
request.setAttribute("vaccination_cardList", userservice.findDate());
} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
e.printStackTrace();
}


request.getRequestDispatcher("/jsps/vaccination_card/displayDoseDate.jsp").forward(request, response);
}

}
28 changes: 26 additions & 2 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<servlet-name>UserServletRegister</servlet-name>
<url-pattern>/UserServletRegister</url-pattern>
</servlet-mapping>


<servlet>
<description></description>
<display-name>UserServletLogin</display-name>
Expand All @@ -82,6 +84,17 @@
<url-pattern>/UserServletLogout</url-pattern>
</servlet-mapping>

<servlet>
<description></description>
<display-name>InitializeDB</display-name>
<servlet-name>InitializeDB</servlet-name>
<servlet-class>user.web.servlet.UserServletRegister</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InitializeDB</servlet-name>
<url-pattern>/InitializeDB</url-pattern>
</servlet-mapping>

<servlet>
<description></description>
<display-name>student_contact_infoServletCreate</display-name>
Expand Down Expand Up @@ -264,14 +277,25 @@
<servlet>
<description></description>
<display-name>findAll</display-name>
<servlet-name>findAll</servlet-name>

<servlet-name>findAll</servlet-name>
<servlet-class>user.web.servlet.findAll</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>findAll</servlet-name>
<url-pattern>/findAll</url-pattern>
</servlet-mapping>

<servlet>
<description></description>
<display-name>displayDoseDate</display-name>
<servlet-name>displayDoseDate</servlet-name>
<servlet-class>vaccination_card.web.servlet.displayDoseDate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>displayDoseDate</servlet-name>
<url-pattern>/displayDoseDate</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>login.jsp</welcome-file>
Expand Down
33 changes: 33 additions & 0 deletions src/main/webapp/jsps/initialize/init.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Initialize Database</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<h1>Initialize Database</h1>

<p style="color: red; font-weight: 900">${msg }</p>
<form action="<c:url value='/UserServletRegister'/>" method="post">


<input type="submit" value="Initialize DB"/>
</form>
</body>
</html>
1 change: 1 addition & 0 deletions src/main/webapp/jsps/top.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<c:when test="${empty sessionScope.session_user }">
<a href="<c:url value='/jsps/user/login.jsp'/>" target="_parent">Login</a> |&nbsp;
<a href="<c:url value='/jsps/user/regist.jsp'/>" target="_parent">Register</a> |&nbsp;
<%-- <a href="<c:url value='/jsps/initialize/init.jsp'/>" target="body">Initialize Database</a> |&nbsp;&nbsp; --%>

</c:when>
<c:otherwise>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/jsps/user/q1_list_users.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
</c:forEach>
</table>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions src/main/webapp/jsps/user/queries.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<h1>Welcome to the Demo</h1>
<br>
<a href="<c:url value='/findAll'/>" target="body">Please list all the user in the table</a>&nbsp;&nbsp;


<br/>
<a href="<c:url value='/displayDoseDate'/>" target="body">Find the First Dose and Second Dose Date</a>&nbsp;&nbsp;
</body>
</html>
28 changes: 28 additions & 0 deletions src/main/webapp/jsps/vaccination_card/displayDoseDate.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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=UTF-8">

</head>
<body>
<h3 align="center"> Display Dose Date </h3>
<table border="1" width="70%" align="center">
<tr>
<th>First_Dose</th>
<th>Second_Dose</th>
</tr>
<c:forEach items="${vaccination_cardList}" var="vaccination_card">
<tr>
<td>${vaccination_card.first_dose}</td>
<td>${vaccination_card.second_date}</td>
</tr>
</c:forEach>
</table>
</body>
</html>



0 comments on commit 040091c

Please sign in to comment.