0% found this document useful (0 votes)
33 views17 pages

Implementation of Add, Delete and Search Employee From Database

The document describes the implementation of adding, deleting, and searching employee records from a database using Java Server Pages (JSP). It includes JSP pages for the admin homepage, data entry form, adding data to the database, deleting a record, searching for a record, and a login page.

Uploaded by

Gaurav Sahu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views17 pages

Implementation of Add, Delete and Search Employee From Database

The document describes the implementation of adding, deleting, and searching employee records from a database using Java Server Pages (JSP). It includes JSP pages for the admin homepage, data entry form, adding data to the database, deleting a record, searching for a record, and a login page.

Uploaded by

Gaurav Sahu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Implementation of Add, Delete and Search Employee From DataBase

<%@page contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>JSP Page</title> </head> <body> <center><h1><font face="Book Anitiqua">Admin Page</font></h1><br> <table> <tr><td><a href="Add.jsp"><font face="Calibri" size="+2">Add Employee</font></a></td></tr> <tr><td><a href="Search.jsp"><font face="Calibri" size="+2">Search Employee</font></a></td></tr> <tr><td><a href="Delete.jsp"><font face="Calibri" size="+2">Delete Employee</font></a></td></tr> </table> </center> </body> </html>

Employee Data Entry Form


<%@page contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>JSP Page</title> </head> <body> <form method="post" action="Add_Emp.jsp"> <center><h1><font face="Book Anitiqua">Data Entry Page...!!!!</font></h1><br> <table border="1"> <tr><td><font face="Calibri" size="+2">Employee ID</font></td><td><input type="text" name="eid"></td></tr> <tr><td><font face="Calibri" size="+2">Employee First Name</font></td><td><input type="text" name="fname"></td></tr> <tr><td><font face="Calibri" size="+2">Employee Last Name</font></td><td><input type="text" name="lname"></td></tr> <tr><td><font face="Calibri" size="+2">Employee Department</font></td><td><input type="text" name="dept"></td></tr> <tr><td><font face="Calibri" size="+2">Employee Designation</font></td><td><input type="text" name="desig"></td></tr> <tr><td><font face="Calibri" size="+2">Employee Age</font></td><td><input type="text" name="age"></td></tr> <tr><td><font face="Calibri" size="+2">Employee Mobile No.</font></td><td><input type="text" name="phno"></td></tr> <tr><td><font face="Calibri" size="+2">Employee E-Mail</font></td><td><input type="text" name="email"></td></tr> <tr><td colspan="2"><center><input type="submit" value="Submit"></center></td> </table> </center> </form> </body> </html>

Add Employee Data To DataBase


<%@page import="javax.sql.*,java.sql.*,java.io.*" contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>JSP Page</title> </head> <body> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:MyDSN"); PreparedStatement pstmt = con.prepareStatement("insert into empdata values (?,?,?,?,?,?,?,?)"); pstmt.setString(1,request.getParameter("eid")); pstmt.setString(2,request.getParameter("fname")); pstmt.setString(3,request.getParameter("lname")); pstmt.setString(4,request.getParameter("dept")); pstmt.setString(5,request.getParameter("desig")); pstmt.setInt(6,Integer.parseInt(request.getParameter("age"))); pstmt.setString(7,request.getParameter("phno")); pstmt.setString(8,request.getParameter("email")); int a=pstmt.executeUpdate(); if(a==1) { %> <center><h1><font face="Book Anitiqua">Your information has been stored....!!!!</font> </h1></center> <% } else { %> <font color="red"><b>Not stored!</b></font>

<% } }catch(ClassNotFoundException e){ }catch(SQLException e){ }catch(Exception e){ } %> </body> </html>

Delete Record of Employee


<%@page contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>Delete Record</title> </head> <body><center><h1><font face="Book Anitiqua">Delete Record of Employee...!!!!</font></h1> <form method="get" action="Delete_Emp.jsp"> <font face="Calibri" size="+2">Enter Employee ID to Delete </font><input type="text" name="eid"> <input type="submit" name="Search"> </form></center> </body> </html>

<%@page import="javax.sql.*,java.sql.*,java.io.*" contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>JSP Page</title> </head> <body> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:MyDSN"); PreparedStatement pstmt = con.prepareStatement("delete from empdata where eid = ?"); pstmt.setString(1, request.getParameter("eid")); int a= pstmt.executeUpdate(); if(a==1) { %> <center><h1><font face="Book Anitiqua">Record has been deleted!!!</font></h1></center> <% } else { %> <center><h1><font face="Book Anitiqua">Record Not Found...!!!!</font></h1></center> <% } }catch(ClassNotFoundException e){ }catch(SQLException e){ }catch(Exception e){ } %> </body> </html>

Search Record From DataBase


<%@page contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>Search Record</title> </head> <body><center><h1><font face="Book Anitiqua">Search Record of Employee...!!!!</font></h1> <form method="get" action="Search_Emp.jsp"> <font face="Calibri" size="+2">Enter Employee ID to Search</font> <input type="text" name="eid"> <input type="submit" name="Search"> </form></center> </body> </html>

<%@page import="javax.sql.*,java.sql.*,java.io.*" contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>JSP Page</title> </head> <body> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:MyDSN"); PreparedStatement pstmt = con.prepareStatement("select * from empdata where eid = ?"); pstmt.setString(1, request.getParameter("eid")); ResultSet rst = pstmt.executeQuery(); if(rst.next()) { %> <center> <h1><font face="Book Anitiqua"> Employee Details...!!!!</font></h1>

<table border="1"> <tr><td><font face="Calibri" size="+2">ID</font></td><td><font face="Calibri" size="+2"><%=rst.getString("eid")%></font></td></tr> <tr><td><font face="Calibri" size="+2">First Name</font></td><td><font face="Calibri" size="+2"><%=rst.getString("fname")%></font></td></tr> <tr><td><font face="Calibri" size="+2">Last Name</font></td><td><font face="Calibri" size="+2"><%=rst.getString("lname")%></font></td></tr> <tr><td><font face="Calibri" size="+2">Department</font></td><td><font face="Calibri" size="+2"><%=rst.getString("dept")%></font></td></tr> <tr><td><font face="Calibri" size="+2">Designation</font></td><td><font face="Calibri" size="+2"><%=rst.getString("desig")%></font></td></tr> <tr><td><font face="Calibri" size="+2">Age</font></td><td><font face="Calibri" size="+2"><%=rst.getInt("age")%></font></td></tr> <tr><td><font face="Calibri" size="+2">Phone No.</font></td><td><font face="Calibri" size="+2"><%=rst.getString("phno")%></font></td></tr>

<tr><td><font face="Calibri" size="+2">E-Mail</font></td><td><font face="Calibri" size="+2"><%=rst.getString("email")%></font></td></tr> </table> </center> <% } else { %> <center><h1><font face="Book Anitiqua">Record Not Found...!!!!</font></h1></center> <% } }catch(ClassNotFoundException e){ }catch(SQLException e){ }catch(Exception e){ } %> </body> </html>

<tr><td><font face="Calibri" size="+2">E-Mail</font></td><td><font face="Calibri" size="+2"><%=rst.getString("email")%></font></td></tr> </table> </center> <% } else { %> <center><h1><font face="Book Anitiqua">Record Not Found...!!!!</font></h1></center> <% } }catch(ClassNotFoundException e){ }catch(SQLException e){ }catch(Exception e){ } %> </body> </html>

Implementation of Login Page in jsp


<%@page contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>Login Page</title> </head> <body> <center><h1><font face="Book Anitiqua">Sign In</font></h1> <form method="POST" action="login.jsp"> <table border="0"> <tr> <td><font face="Calibri" size="+2">User Name</font></td> <td><input type="text" name="uname"></td> </tr> <tr> <td><font face="Calibri" size="+2">Password</font></td> <td> <input type="password" name="pwd"> </td> </tr> </table> <br><input type="submit" value="Login"><input type="reset" value="Reset"> </form> </center> </body> </html>

Login.jsp
<%@page import="java.sql.*,javax.sql.*,java.io.*" contentType="text/html" pageEncoding="UTF-8"%> <!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"> <title>Welcome! </title> </head> <body> <% String uname = request.getParameter("uname"); String pwd = request.getParameter("pwd");

%> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:MyDSN"); PreparedStatement pstmt = con.prepareStatement("select * from info where uname = ? and password = ?"); pstmt.setString(1, uname); pstmt.setString(2, pwd); ResultSet rst = pstmt.executeQuery(); if(rst.next()) { %> <jsp:forward page="home.jsp" ></jsp:forward> <% } else{ %> <jsp:include page="index.jsp"></jsp:include> <% } }

catch(ClassNotFoundException e){ }catch(SQLException e){ out.println(e); }catch(Exception e){ } %>

</body> </html>

You might also like