Bookmark Topic Watch Topic
  • New Topic

JSP, Servlet, DB help?

 
Lars Ulrich
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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 ]
 
Thomas Harrington
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
nirav soni parmar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ok.. I will remember next Time.

Thank You.
 
Tom Joiner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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.
 
Karthik Srikanti
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
I don't really think there's a need to answer a 3 1/2 year old question.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic