User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 374,010 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,872 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1149 | Replies: 3 | Solved
Reply
Join Date: May 2008
Posts: 6
Reputation: ashish1234 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
ashish1234 ashish1234 is offline Offline
Newbie Poster

how to delete multiple records using jsp

  #1  
May 7th, 2008
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

  1. <html>
  2. <body>
  3.  
  4. <table width="50%" border="1" rules=ALL>
  5. <tr><th> Username</th><th>Access Level</th><th>Delete</th></tr>
  6. <%@ page language="java" import="java.sql.*" %>
  7. <%
  8. int j=0;
  9. Connection con =null;
  10. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  11. con=DriverManager.getConnection("jdbc:odbc:udsn","","");
  12. Statement st=con.createStatement();
  13. ResultSet rs=st.executeQuery("select * from staff");
  14.  
  15. while (rs.next())
  16. { j=j+1;%>
  17. <tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr>
  18.  
  19.  
  20. <%}
  21.  
  22. %>
  23. <form action="deleteuser.jsp">
  24. <input type="hidden" name="recordcount" value="<%=j%>">
  25. <input type="submit" name="b1" value="Delete" >
  26. </table>
  27. </form>
  28. </body>
  29. </html>


how to do the second part...any one to help me plzzzz....
Last edited by peter_budo : May 9th, 2008 at 7:27 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,907
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 9
Solved Threads: 216
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Posting Virtuoso

Re: how to delete multiple records using jsp

  #2  
May 9th, 2008
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 follows
  1. JSP - to collect data
  2. Servlet - execute logic
    • Data retrival
    • Validation
    • Connection to DB
    • Retriving any data from DB
    • Possibly saving in session
  3. JSP - to display outcome
Validation also can be done on the JSP befor submit, but then you have to know JavaScript or similar
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: Sprashant is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Sprashant Sprashant is offline Offline
Newbie Poster

Re: how to delete multiple records using jsp

  #3  
Jun 9th, 2008
  1. <html>
  2. <body>
  3.  
  4. <table width="50%" border="1" rules=ALL>
  5.  
  6. <tr><th> Username</th><th>Access Level</th><th>Delete</th></tr>
  7.  
  8. <%@ page language="java" import="java.sql.*" %>
  9.  
  10. <%
  11.  
  12. int j=0;
  13.  
  14. Connection con =null;
  15.  
  16. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  17.  
  18. con=DriverManager.getConnection("jdbc:odbc:udsn","","");
  19.  
  20. Statement st=con.createStatement();
  21.  
  22. ResultSet rs=st.executeQuery("select * from staff");
  23.  
  24.  
  25.  
  26. while (rs.next())
  27.  
  28. { j=j+1;%>
  29.  
  30. <tr><td align="center"><%=rs.getString(1)%></td><td align="center"><%=rs.getString(3)%></td><td><input type="checkbox" name="delete" value="yes"></tr>
  31.  
  32. <%}
  33.  
  34. %>
  35.  
  36. <form action="deleteuser.jsp">
  37.  
  38. <input type="hidden" name="recordcount" value="<%=j%>">
  39.  
  40. <input type="submit" name="b1" value="Delete" >
  41.  
  42. </table>
  43.  
  44. </form>
  45.  
  46. </body>
  47.  
  48. </html>
  49.  
  50. <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>
Last edited by peter_budo : Jun 9th, 2008 at 3:02 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 187
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how to delete multiple records using jsp

  #4  
Jun 9th, 2008
and don't revive old dead threads to post nonsense "solutions".
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 10:46 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC