*
The moose likes EJB and other Java EE Technologies and the fly likes deleting a record with cmp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "deleting a record with cmp" Watch "deleting a record with cmp" New topic
Author

deleting a record with cmp

alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
please i am really in a big problem.
can any one please tell me how to update and delete a record from a persistence data storage like sql server 2000 using cmp bean
thanks in advance

Johann Evans
Ranch Hand

Joined: Nov 18, 2002
Posts: 47
Use the specific interface's remove() method or update the fields using the getters and setters.

I.e.

ABean - Entity Bean class
A - Remote Interface
AHome - Remote Home interface

A.remove(); - deletes the record
A.setName("abc"); - updates the field

Or use ValueObject pattern for updates...
alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
now too i am unable to delete

my remove method in StoryBean.java
public void remove()throws RemoteException
{
try
{
Context ic = new InitialContext();
Object o = ic.lookup("ejb/Example/Story");
StoryHome home = (StoryHome) PortableRemoteObject.narrow(o, StoryHome.class);
Story story=home.findByPrimaryKey(new Integer(6));
Collection stories = home.findAll();
stories.remove(story);
}
catch(Exception ex)
{

}
}

i am calling this method in jsp as such:

<%@page import="java.rmi.*" %>
<%@page import="java.util.*" %>
<%@page import="javax.naming.*" %>
<%@page import="javax.rmi.*" %>
<%@page import="teste.*" %>
<html>
<head><title>Story</title></head>
<body>
<%
try {
Context ic = new InitialContext();
Object o = ic.lookup("ejb/Example/Story");
StoryHome home = (StoryHome)
PortableRemoteObject.narrow(o, StoryHome.class);
Collection stories = home.findAll();
Story story=home.findByName(new String("sanjay"));
story.remove();
for (Iterator i = stories.iterator(); i.hasNext(); ) {
story = (Story) i.next();
out.println(story.getStoryId());
out.println(story.getName());

}
story.remove();
} catch (Exception ex) {
out.println(ex);
}
%>
</body>
</html>
Johann Evans
Ranch Hand

Joined: Nov 18, 2002
Posts: 47
Your JSP code is fine - the remove() method is part of the interface - don't implement it!

In other words, you don't need to write any code - drop the remove() method from your Bean class - not needed!
alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
thnks Johann Evans
my problem has been sorted as directed by you.
i am very thankful to you for taking time and interest in solving my problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deleting a record with cmp