-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.java
187 lines (171 loc) · 8.58 KB
/
Server.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import java.io.IOException;
import java.sql.*;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Server extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
try
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
System.out.println(request);
String res= request.getParameter("responsibility");
String awards= request.getParameter("awards");
String publications= request.getParameter("publications");
String phd=request.getParameter("phd");
String max=request.getParameter("max");
String year=request.getParameter("year");
String query=request.getParameter("query");
ResultSet rs;
// System.out.println("Selected "+res+" , "+awards+" , "+publications+","+phd);
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mydb", "root", "heer");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
if (!query.equals(""))
{
rs=stmt.executeQuery(query+"");
while(rs.next())
{
ResultSetMetaData rsmd = rs.getMetaData();
String name=rs.getString("fac_name");
int columnsNumber = rsmd.getColumnCount();
StringBuffer data =new StringBuffer("");
StringBuffer data1 =new StringBuffer("");
int i;
if(columnsNumber!=0)
{
for(i=1;i<=columnsNumber;i++)
{
data1=new StringBuffer(rsmd.getColumnName(i));
data=new StringBuffer(rs.getString(i));
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n"
+data1.toString().toUpperCase()+"</b></h2>"+
"<p>"+data+"</p>"+
"</body></html>");
}
}
else
{
response.sendRedirect("userhome.html");
}
}
}
if(!res.equals("Select Responsibility"))
{
rs = stmt.executeQuery("select * from Fac_Details where responsibility='"+res+"'");
while(rs.next())
{
String name=rs.getString("fac_name");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n" +
"<h2>"+name+" has responsibilty "+res+"</h2>"+
"</body></html>");
}
}
if(!awards.equals("Select Awards"))
{
rs = stmt.executeQuery("select fac_name from awards where award_name='"+awards+"'");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n"
+"<html><head><title>RESPONSE</title></head><body>";
while(rs.next())
{
String name=rs.getString("fac_name");
out.println(docType +
"<h2> "+name+" got "+awards+"</h2>"+
"</body></html>");
}
}
if(!publications.equals("Select Publication"))
{
rs = stmt.executeQuery("select fac_name from publication where paper_name='"+publications+"'");
while(rs.next())
{
String name=rs.getString("fac_name");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n" +
"<h2> "+name+" published "+publications+"</h2>"+
"</body></html>");
}
}
if(!year.equals("Select Year"))
{
rs = stmt.executeQuery("select fac_name ,count(paper_name),year from publication group by year having year=\""+year+"\";");
while(rs.next())
{
String name=rs.getString("fac_name");
String count=rs.getString("count(paper_name)");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n" +
"<h2>Max Paper in the year "+year+" is by "+name+" and count is "+count+" </h2>"+
"</body></html>");
}
}
if(max.equals("YES"))
{
rs = stmt.executeQuery("select fac_name ,count(project_name) from projects group by fac_name order by count(project_name) desc limit 1;");
while(rs.next())
{
String name=rs.getString("fac_name");
String count=rs.getString("count(project_name)");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n" +
"<h2>"+name+" Have Maximum Current Projects and count is "+count+"</h2>"+
"</body></html>");
}
}
if(phd.equals("YES"))
{
rs = stmt.executeQuery("select fac_name ,count(student_name) from phdstudents group by fac_name order by count(student_name) desc limit 1;");
while(rs.next())
{
String name=rs.getString("fac_name");
String count=rs.getString("count(student_name)");
String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType + "<html>\n" +
"<head><title>" + "Response"+ "</title></head>\n" +
"<body bgcolor=\"#f0f0f0\">\n" +
"<h1 align=\"center\">" + "RESPONSE" + "</h1>\n" +
"<h2>"+name+" Have Maximum Ph.D Students And Count is "+count+"</h2>"+
"</body></html>");
}
}
else
{
response.sendRedirect("userhome.html");
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}