Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP, Servlet, DB help?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have a JSP page that displays rows of user/password with a check box in front of each user. The administrator will use this to delete users from the DB. How would I set up the Servlet to iterate through the list of checked users and delete them from the DB?
[ September 21, 2006: Message edited by: Bear Bibeault ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I use a bean, so this may be different from what you are looking for but maybe it will help. I have an inner class in my bean which takes a string, and then has a Delete FROM XyourtableX WHERE XnameofvalueqeuriedX = "?". the XyourtableX should be the name of your table, and the XnameofvaluequeriedX should be the value you are using to find the enrty to delete. I use the primary key, as there can only be one and you will not delete multiple entries that way.
The JSP which processes the removal of the checked items should retrieve the values of the checked boxes, probably by using request.getParameter(), where you have some variable equal it and name that whatever you want to pass to the bean.
BTW, there was a great example of what you are trying to do with Begenning JSP Web Services Programming by Wrox. They have an example like what you are trying to do. I think you can download the sample code from their website.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Ok.. I will remember next Time.

Thank You.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In my databases, I never actually "delete" anything. Why? Because you never know when you want to go back and get data, especially something small like a user list. Therefore, I would created your database with a "deleted" column which you them check when the user deletes themselsves. Then, all your queries against the database should obviously ignore the deleted users, unless you are doing some historical analysis of old users.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Give all teh checkboxes the same name something like

<input type="checkbox" id="uid" name="checkValue" value="<primary id in your table>">

Then in the servlet

use

String [] checkValue = request.getParameterValues("checkValue");

String sql = "Delete from users where <primaryid> in ("

for(int i=0;i<checkValue.length;i++)
{
sql+=checkValue[id] + ",";
//Add logic to remove , for last entry
}

Then establish a connection to a database and do something like this

rset.executeUpdate(sql);

Hope that helps..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I don't really think there's a need to answer a 3 1/2 year old question.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic