954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to delete multiple records using jsp

hi,
i am new to jsp..i am trying do sort out a pblm..
i have 2 jsp files..

file1.jsp..
which is used to select all the records from a table called staff and display the records in a table..each record is coming with a check boxes which is used for marking..

i need to select all the records i want to delete and by pressing a submit button i want to delte all the records frm the table..
how is it possible..i wrote the code for the first part..it is like..

page1.jsp

<html>
<body>

<table width="50%" border="1" rules=ALL>
<tr><th> Username</th><th>Access Level</th><th>Delete</th></tr>
<%@ page language="java" import="java.sql.*" %>
<%
int j=0;
Connection con =null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:udsn","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from staff");

while (rs.next())
{ j=j+1;%>
<tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr>


<%}

%> 
<form action="deleteuser.jsp">
<input type="hidden" name="recordcount" value="<%=j%>">
<input type="submit" name="b1" value="Delete" >
</table>
</form>
</body>
</html>

how to do the second part...any one to help me plzzzz....

ashish1234
Newbie Poster
6 posts since May 2008
Reputation Points: 8
Solved Threads: 1
 

JSP is for presentation only (meaning to provide interface for web page), servlet is proper component to setup connection with database. So the process should be as followsJSP - to collect data
Servlet - execute logicData retrival
Validation
Connection to DB
Retriving any data from DB
Possibly saving in session

JSP - to display outcome
Validation also can be done on the JSP befor submit, but then you have to know JavaScript or similar

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 
<html>
<body>

      <table width="50%" border="1" rules=ALL>

      <tr><th> Username</th><th>Access Level</th><th>Delete</th></tr>

      <%@ page language="java" import="java.sql.*" %>

      <%

      int j=0;

      Connection con =null;

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      con=DriverManager.getConnection("jdbc:odbc:udsn","","");

      Statement st=con.createStatement();

      ResultSet rs=st.executeQuery("select * from staff");

       

      while (rs.next())

      { j=j+1;%>

      <tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr>

      <%}

      %>

      <form action="deleteuser.jsp">

      <input type="hidden" name="recordcount" value="<%=j%>">

      <input type="submit" name="b1" value="Delete" >

      </table>

      </form>

      </body>

      </html>

<html> <body> <table width="50%" border="1" rules=ALL> <tr><th> Username</th><th>Access Level</th><th>Delete</th></tr> <%@ page language="java" import="java.sql.*" %> <% int j=0; Connection con =null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:udsn","",""); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from staff"); while (rs.next()) { j=j+1;%> <tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr> <%} %> <form action="deleteuser.jsp"> <input type="hidden" name="recordcount" value="<%=j%>"> <input type="submit" name="b1" value="Delete" > </table> </form> </body> </html>
Sprashant
Newbie Poster
3 posts since May 2008
Reputation Points: 7
Solved Threads: 1
 

and don't revive old dead threads to post nonsense "solutions".

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You