GTU Advance Java Practical- 4
Implement student registration form with enrollment number, first name, last name, semester, contact number. Store the details in database. Also implement search, delete and modify facility for student records.
Form.jsp
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Insert.jsp">
<table border="1px solid black">
<tr>
<td>ENROLLMENT_NUMBER: </td>
<td><input type="text" name="en"></td>
</tr>
<tr>
<td>FIRSTNAME: </td>
<td><input type="text" name="fn"></td>
</tr>
<tr>
<td>LASTNAME: </td>
<td><input type="text" name="ln"></td>
</tr>
<tr>
<td>SEMESTER: </td>
<td><input type="text" name="se"></td>
</tr>
<tr>
<td>CONTACT_NUMBER: </td>
<td><input type="text" name="no"></td>
</tr>
<tr>
<td><input type="submit" value="Save"></td>
</tr>
</table>
</form>
<a href="Search.jsp">Search</a>
</body>
</html>

				
			
Insert.jsp:
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String en = request.getParameter("en");
String fn = request.getParameter("fn");
String ln = request.getParameter("ln");
String se = request.getParameter("se");
String no = request.getParameter("no");
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/manual","root","root");
Statement s2 = c.createStatement();
s2.executeUpdate("insert into Prac5(Enrollment,Firstname,Lastname,Semester,Contactno)
values('"+en+"','"+fn+"','"+ln+"','"+se+"','"+no+"')");
s2.close();
c.close();
response.sendRedirect("Form.jsp");
%>
</body>
</html>

				
			
Search.jsp:
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/manual","root","root");
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select* from Prac5");
%>
<table border="1px solid black">
<tr>
<th>ID</th>
<th>ENROLLMENT_NUMBER</th>
<th>FIRSTNAME</th>
<th>LASTNAME</th>
<th>SEMESTER</th>
<th>CONTACT_NUMBER</th>
<th>Action</th>
</tr>
<%
while(rs.next())
{
int id = rs.getInt("id");
String en = rs.getString("Enrollment");
String fn = rs.getString("Firstname");
String ln = rs.getString("Lastname");
String se = rs.getString("Semester");
String no = rs.getString("Contactno");
%>
<tr>
<td><% out.println(id);%></td>
<td><% out.println(en);%></td>
<td><% out.println(fn);%></td>
<td><% out.println(ln);%></td>
<td><% out.println(se);%></td>
<td><% out.println(no);%></td>
<td><a href="Delete.jsp?x=<%=id%>">Delete</a></td>
<td><a href="Edit.jsp?y=<%=id%>">Edit</a></td>
</tr>
<%
}
%>
</body>
</html>
				
			
Edit.jsp:
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
int id = Integer.parseInt(request.getParameter("y"));
int i=0;
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/manual","root","root");
Statement st = c.createStatement();
ResultSet rs =st.executeQuery("select * from Prac5 where id = "+ id);
%>
<%
while(rs.next())
{
int id1 = rs.getInt("id");
String en = rs.getString("Enrollment");
String fn = rs.getString("Firstname");
String ln = rs.getString("Lastname");
String se = rs.getString("Semester");
String no = rs.getString("Contactno");
%>
<form action="Update.jsp">
<table border="1px solid black">
<tr>
<td><input type="hidden" name="id1" value='<%=id1%>'></td>
</tr>
<tr>
<td>ENROLLMENT_NUMBER: </td>
<td><input type="text" name="en" value="<%=en%>"></td>
</tr>
<tr>
<td>FIRSTNAME: </td>
<td><input type="text" name="fn" value="<%=fn%>"></td>
</tr>
<tr>
<td>LASTNAME: </td>
<td><input type="text" name="ln" value="<%=ln%>"></td>
</tr>
<tr>
<td>SEMESTER: </td>
<td><input type="text" name="se" value="<%=se%>"></td>
</tr>
<tr>
<td>CONTACT_NUMBER: </td>
<td><input type="text" name="no" value="<%=no%>"></td>
</tr>
<tr>
<td><input type="submit" value="Update"></td>
</tr>
</table>
</form>
<%
}
c.close();
st.close();
%>
</body>
</html>
				
			
Update.jsp:
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
int id =Integer.parseInt( request.getParameter("id1"));
String en = request.getParameter("en");
String fn = request.getParameter("fn");
String ln = request.getParameter("ln");
String se = request.getParameter("se");
String no = request.getParameter("no");
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/manual","root","root");
Statement st =c.createStatement();
st.executeUpdate("update Prac5 set Enrollment='"+en+"', Firstname='"+fn+"',
Lastname='"+ln+"',
Semester='"+se+"', Contactno='"+no+"' where id='"+id+"'");
st.close();
c.close();
response.sendRedirect("Search.jsp");
%>
</body>
</html>
				
			
Delete.jsp:
				
					<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
int id = Integer.parseInt(request.getParameter("x"));
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost:3306/manual","root","root");
Statement st = c.createStatement();
st.executeUpdate("delete from Prac5 where id="+id);
st.close();
c.close();
response.sendRedirect("Search.jsp");
%>
</body>
</html>