I am developing a web application in which I have a jsp page with table. The table is populated by values of database except for one column which is editable and empty for user to enter the data. My problem is I want to update the database table once the user enters the data into editable cells and press submit button. Can anyone help me on this. Below is my code of jsp page.
<%@ 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">
<%@ page import="com.employee.com.LoginDetails" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="css/NewFile2.css">
</head>
<body>
<img src="images/Crevavi_Plain.jpg" background-color="white" width="300" height="70" style="float:right; margin-right:200px;"/></br>
<h1 style="margin-left:20px; margin-top:10px;"><font size="8" color="Black"> Notification </font></h1>
<fieldset style="float: center; width:1680px; height:900px; background-color:white; border-color:black; margin-top:10px;"></br></br>
<link rel="stylesheet" href="css/table.css">
<fieldset style="float: center; width:250px; height: 450px; background-color:white; border-color:black; margin-top:10px;margin-left:10px;">
<fieldset style="float: center; width:900px; height:600px; background-color:; border-color:grey; margin-left:275px; margin-top:-450px;"></br>
<link rel="stylesheet" href="css/table.css">
<%
final String UserName,Password;
String name="",employeeid="",projectmanager="";
UserName = LoginDetails.username;
Password = LoginDetails.password;
String employname="",employId="",fromdate="",todate="",reason="";
ResultSet resultset = null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Statement statement = null;
try {
statement = connection.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
resultset = statement.executeQuery("SELECT * FROM employmanage WHERE Username = '"+UserName+"'");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(resultset.next()){
projectmanager = resultset.getString(1);
}
}catch(Exception e){
e.printStackTrace();
}
try {
resultset = statement.executeQuery("SELECT * FROM leavedetails WHERE Projectmanager = '"+projectmanager+"'");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {%>
<TABLE>
<TR>
<TH>Employee Name</TH>
<TH>Employee ID</TH>
<TH>From Date</TH>
<TH>To Date</TH>
<TH>Reason</TH>
<TH>Status</TH>
</TR>
<% while(resultset.next()){ %>
<TR>
<TD> <%= resultset.getString(1) %></TD>
<TD> <%= resultset.getString(2) %></TD>
<TD> <%= resultset.getString(4) %></TD>
<TD> <%= resultset.getString(5) %></TD>
<TD> <%= resultset.getString(6) %></TD>
<TD contenteditable='true' %></TD>
<% }
}catch(Exception e){
e.printStackTrace();
}
%>
</fieldset>
</body></html>