Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

deleting a record with cmp

 
alec stewart stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic