<html>
<body>
<%@page import="java.sql.*"%>
<form method="post" action="csea.jsp">
<table border="1">
<tr><th>Reg No</th><th>Name</th><th>Present/Absent</th></tr>
<%
      String pa = request.getParameter("pa");
      try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con = DriverManager.getConnection("jdbc:odbc:Student");
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("select * from student_details");
      while (rs.next()) {
%>
<tr><th><%=rs.getString("reg_no")%></th><th><%=rs.getString("s_name")%></th>
     <th><input type="text" name="pa"/></th>
</tr>
<%
       }
       st.executeUpdate("update csea  set pa='"+pa+"'");
       con.close();
       st.close();
       rs.close();
    } catch (Exception e) {
 }%>
</table>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
</body>
</html>

In this code the problem am facing is that when am insert the student status as "present" then it the status is updating to all s_name column

example: suppose they are 3 student are their in msaccess table
reg_no s_name present/absent
1 x present
2 Y present
3 z present
now i want put status as present, absent and present but by this code the all 3 student is showing all present.

Regards,
Abrar.

alright well from what i am reading, you create a table with a row for each students , but put no value in the textbox for the "present/absent" column. Then, you immidiatly update the table with the query :

"update csea set pa='"+pa+"'"

where pa is the parameter from the request.

and finish by adding a button that submits to csea.jsp

Now the problem is that the update statement should be in csea.jsp, not in your current page. also is "csea" also a table in your database? because im just assuming that your update query should update the "student_details" table instead of csea.

also, i guess id give different names for the textboxes instead of "pa" for all of them. Like "pa<%=rs.getString("reg_no")%>" so then you could loop through your students in csea.jsp and fetch "pa"+studentnumber from your request, and if its not null, update that single student with its value.

What is in csea.jsp?

EDIT : i just understood that this page IS csea.jsp , correct? and here is what is happening, the first time the page loads, it prints the form with nothing in textboxes, then updates all students with no info (i still dont understand how your query string can update the table "csea" and not "student_details" but whatever), THEN you fill the form and click the submit button, which calls back the page, prints out the form (with empty textboxes again) and then calls the update query with the request.parameter "pa" , which actually should return an array of parameters since there would be a total of 3 textboxes with the name "pa", (from my experiences with vb and classic asp anyways, I have never tried to retrieve such an array of parameters with jsp but i am assuming it would act somewhat like that).... but the query only updates the table with the first value of the 3 values in the array...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.