index.html
<html>
<body> <form action="UpdateEmp.jsp" >
Enter Employee Number<input type="text" name="txtEno" ><br>
Enter Name<input type="text" name="txtName" ><br>
Enter age<input type="text" name="txtAge" ><br>
Enter Salary<input type="text" name="txtSal" ><br>
<input type="reset" value="Reset" >
<input type="submit" value="submit">
</form>
</body>
</html>
index.html
<%--
Document : UpdateEmp
Created on : Oct 12, 2019, 10:10:02 PM
Author : RupamSolution
--%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<html>
<body>
<h1>Employee Record Update</h1>
<%
String eno=request.getParameter("txtEno");
String name=request.getParameter("txtName");
String age = request.getParameter("txtAge");
String sal = request.getParameter("txtSal");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:derby://localhost:1527/mysql","root","root");
PreparedStatement stmt = con.prepareStatement("select * from emp where empid=?"); stmt.setString(1, eno);
ResultSet rs = stmt.executeQuery();
if(rs.next())
{
out.println("<h1>~~~ Employee "+name+" Exist ~~~ </h1>");
PreparedStatement pst1= con.prepareStatement("update emp set salary=? where empid=?");
PreparedStatement pst2= con.prepareStatement("update emp set age=? where empid=?");
PreparedStatement pst3= con.prepareStatement("update emp set ename=? where empid=?");
pst1.setString(1, sal);
pst1.setString(2, eno);
pst2.setString(1, age);
pst2.setString(2, eno);
pst3.setString(1, name);
pst3.setString(2, eno);
pst1.executeUpdate();
pst2.executeUpdate();
pst3.executeUpdate();
}
else
{
out.println("<h1>Employee Record not exist !!!!!</h1>");
}
}
catch(Exception e)
{
out.println(e);
}
%>
</body>
</html>
0 Comments