aspose file tools*
The moose likes Servlets and the fly likes update record for selection of  id 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 » Servlets
Bookmark "update record for selection of  id" Watch "update record for selection of  id" New topic
Author

update record for selection of id

Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
I had to update the record in the database ,but i am confuse how to do this.
I am getting empid in my servlet page but then i am confuse how to display record on basic of this empid in jsp page. and from there update these record .

My servlet is : UpdateServlet.java



Java page : UserUpdate.java


UserDetails.java
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Nitin,

Generally this type of thing is done by considering primary key of perticular table.

While calling any updation or creation method, first we have to check that primary key,
if it is empty then call creation method and
if that key is non-empty then call updation method.

that means when you are getting the data from that table in bean you should get primary key,if you update some data & click on save than due to that primary key updation method is getting called.primary key you can populate in JSP by using hidden form feild.


Thanks,
Shailesh
Nitin Belaram
Ranch Hand

Joined: Mar 24, 2009
Posts: 67
Shail Narkhede wrote:Nitin,

Generally this type of thing is done by considering primary key of perticular table.

While calling any updation or creation method, first we have to check that primary key,
if it is empty then call creation method and
if that key is non-empty then call updation method.

that means when you are getting the data from that table in bean you should get primary key,if you update some data & click on save than due to that primary key updation method is getting called.primary key you can populate in JSP by using hidden form feild.



My empid is primary key and i am getting it value ,Please suggest how to get all row value corresponding to this empid , and how to display them in form for updation
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
I think you are using your custom controller.
If you use Struts for this, their is custom tags available for all these thing.

anyway you can acheive this by,
add getter & setter for each feild in UserUpdate class.

write your jsp with one form tag with action="UpdateServlet"(url pattern in DD of UpdateServlet).
then write text tags with name simillar to name in "UserUpdate" class feild.
due to that while submitting all feild is passed with request as parameter. you can get them by request.getParameter().

Now for displaying data You can use scriptlets in scriptlet you will get "UserUpdate" from session.(which is set in session by getting fron DB before forwarding to jsp)
now in value attribute of text tag write expression there get value from getter of that perticular feild.
actually this is not good solution, but I thing we can do this way.

You can also do this by custom tags for text feild.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: update record for selection of id