wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP, Servlet, DB help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic
Author

JSP, Servlet, DB help?

Lars Ulrich
Greenhorn

Joined: Dec 03, 2002
Posts: 3
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

Joined: Mar 29, 2003
Posts: 22
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

Joined: Aug 22, 2006
Posts: 15
Ok.. I will remember next Time.

Thank You.
Tom Joiner
Ranch Hand

Joined: Sep 19, 2006
Posts: 47
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.


SCJP
Karthik Srikanti
Greenhorn

Joined: Sep 20, 2006
Posts: 11
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..


{ SCJP, SCWCD, SCBCD, OCA (DBA) }
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61429
    
  67

I don't really think there's a need to answer a 3 1/2 year old question.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP, Servlet, DB help?