Skip to content

Commit

Permalink
lab 9 works
Browse files Browse the repository at this point in the history
  • Loading branch information
geunchanKim committed Nov 21, 2023
1 parent a09023a commit 0791a77
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 14 deletions.
7 changes: 6 additions & 1 deletion KNU_MUSEUM/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.5">
<attributes>
Expand All @@ -9,5 +13,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="C:/oracle/ojdbc11.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
13 changes: 0 additions & 13 deletions KNU_MUSEUM/src/main/webapp/NewFile.jsp

This file was deleted.

147 changes: 147 additions & 0 deletions KNU_MUSEUM/src/main/webapp/response.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page language="java" import="java.text.*,java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>COMP322: Introduction to Databases</title>
</head>
<body>
<%
String serverIP = "localhost";
String strSID = "orcl";
String portNum = "1521";
String user = "Company";
String pass = "comp322";
String url = "jdbc:oracle:thin:@"+serverIP+":"+portNum+":"+strSID;
String query = new String();
Connection conn = null;
PreparedStatement pstmt;
ResultSet rs;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url,user,pass);
%>

<h2>Lab #9: Repeating Lab #5-3 via JSP</h2>
<h4>------ Q1 Result --------</h4>

<%
//Q1
query = "Select E.Fname, E.Lname, E.Salary from Employee E, Project P, Works_on W"
+ " Where P.Pnumber = W.Pno and W.Essn = E.Ssn and P.Pname LIKE '"+ request.getParameter("Project1")
+ "' and E.Dno = " + request.getParameter("Dnum") + " and E.Salary >= " + request.getParameter("Salary");
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
out.println("<table border=\"1\">");
ResultSetMetaData rsmd = rs.getMetaData();
int cnt = rsmd.getColumnCount();
for(int i =1;i<=cnt;i++){
out.println("<th>"+rsmd.getColumnName(i)+"</th>");
}
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getFloat(3) + "</td>");
out.println("</tr>");
}
out.println("</table>");
%>
<h4>------ Q2 Result --------</h4>
<%
//Q2
query = "Select D.Dname, E.Ssn, E.Fname, E.Lname from Employee E, Department D " +
"Where E.Dno = D.Dnumber and E.Super_ssn = '" + request.getParameter("SSN1") +"' and E.Address LIKE '%" + request.getParameter("address") +"%'";
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
out.println("<table border=\"1\">");
rsmd = rs.getMetaData();
cnt = rsmd.getColumnCount();
for(int i =1;i<=cnt;i++){
out.println("<th>"+rsmd.getColumnName(i)+"</th>");
}
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getString(3) + "</td>");
out.println("<td>" + rs.getString(4) + "</td>");
out.println("</tr>");
}
out.println("</table>");
%>
<h4>------ Q3 Result --------</h4>
<%
//Q3
query = "Select E.Fname, E.Lname, W.Hours from Employee E, Project P, Works_on W " +
"Where E.Ssn = W.Essn and P.Pnumber = W.Pno and P.Pname = '" + request.getParameter("Project3") +"' and W.Hours >=" + request.getParameter("hour3");
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
out.println("<table border=\"1\">");
rsmd = rs.getMetaData();
cnt = rsmd.getColumnCount();
for(int i =1;i<=cnt;i++){
out.println("<th>"+rsmd.getColumnName(i)+"</th>");
}
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getInt(3) + "</td>");
out.println("</tr>");
}
out.println("</table>");
%>
<h4>------ Q4 Result --------</h4>
<%
//Q4
query = "Select DISTINCT D.Dname, E.Fname, E.Lname from Employee E, Project P, Works_on W, Department D " +
"Where E.Ssn = W.Essn and P.Pnumber = W.Pno and P.Dnum = D.Dnumber and P.Pname LIKE '%" + request.getParameter("Project4") +"%' and W.Hours >=" + request.getParameter("hour4");
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
out.println("<table border=\"1\">");
rsmd = rs.getMetaData();
cnt = rsmd.getColumnCount();
for(int i =1;i<=cnt;i++){
out.println("<th>"+rsmd.getColumnName(i)+"</th>");
}
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getString(3) + "</td>");
out.println("</tr>");
}
out.println("</table>");
%>
<h4>------ Q5 Result --------</h4>
<%
//Q5
query = "Select D.Dname, E.Lname, E.Fname, DE.Dependent_name from Dependent DE, Employee E, Department D " +
"Where E.Dno = D.Dnumber and E.Ssn = DE.Essn and DE.Relationship = 'Spouse' and E.Super_ssn = " + request.getParameter("SSN5");
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
out.println("<table border=\"1\">");
rsmd = rs.getMetaData();
cnt = rsmd.getColumnCount();
for(int i =1;i<=cnt;i++){
out.println("<th>"+rsmd.getColumnName(i)+"</th>");
}
while(rs.next()){
out.println("<tr>");
out.println("<td>" + rs.getString(1) + "</td>");
out.println("<td>" + rs.getString(2) + "</td>");
out.println("<td>" + rs.getString(3) + "</td>");
out.println("<td>" + rs.getString(4) + "</td>");
out.println("</tr>");
}
out.println("</table>");
%>
<%
rs.close();
pstmt.close();
conn.close();
%>
</body>
</html>
65 changes: 65 additions & 0 deletions KNU_MUSEUM/src/main/webapp/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>COMP322: Introduction to Databases</title>
</head>
<body>
<h2>Lab #9: Repeating #5-3 vis JSP</h2>

<form action="response.jsp" method="POST" style="display: inline;">
<h3>Query 1: Search for employees satisfying the following conditions:</h3>
Project name starting with:
<select name="Project1">
<option value="ProductX">ProductX</option>
<option value="ProductY">ProductY</option>
<option value="ProductZ">ProductZ</option>
<option value="Computerization">Computerization</option>
<option value="Reorganization">Reorganization</option>
<option value="Newbenefits">Newbenefits</option>
</select>
Department number:
<select name="Dnum">
<option value="1">1</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
Salary greater than or equal to:
<input type="text" name="Salary"/>
<br/><br/>
<h3>Query 2: Search for employees satisfying the following conditions:</h3>
Supervisor's SSN:
<input type="text" name="SSN1"/>
Address including:
<input type="text" name="address"/>
<br/><br/>
<h3>Query 3: Search for employees working on:</h3>
Project name:
<select name="Project3">
<option value="ProductX">ProductX</option>
<option value="ProductY">ProductY</option>
<option value="ProductZ">ProductZ</option>
<option value="Computerization">Computerization</option>
<option value="Reorganization">Reorganization</option>
<option value="Newbenefits">Newbenefits</option>
</select>
Working hours more than:
<input type="number" name="hour3"/>
<br/><br/>
<h3>Query 4: Search for employees working on:</h3>
Project name starting with:
<input type="text" name="Project4"/>
<br/>
Working hours greater than or equal to:
<input type="number" name="hour4"/>
<br/><br/>
<h3>Query 5: Search for a supervisee(s) and his/her spouse(s) with:</h3>
Supervisor's SSN:
<input type="text" name="SSN5"/>
<br/><br/>
<input type = "reset" value = "Reset">
<input type = "submit" value = "Submit"/>
</form>

</body>
</html>

0 comments on commit 0791a77

Please sign in to comment.