944,149 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6995
  • Java RSS
Mar 27th, 2007
0

How to call a EJB method from Session bean method

Expand Post »
Hi all,

I'm new to J2EE programming. I have a simple doubt .

I have already created a lookup method for EJB bean in Session bean .

My question is how to call a method of an ENTITY bean (say insertRow) from SESSION bean method(Say invoke_insertRow) .

Please provide me an example code .

Thanks in advance.
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
parthiban is offline Offline
80 posts
since Sep 2006
Mar 28th, 2007
0

Re: How to call a EJB method from Session bean method

You don't.
You create a new entity, and it takes care of its database access itself.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 28th, 2007
0

Re: How to call a EJB method from Session bean method

Click to Expand / Collapse  Quote originally posted by jwenting ...
You don't.
You create a new entity, and it takes care of its database access itself.
Hi Jwenting ,
First of all thanks for your reply . I think i didn't correctly specified what i need .

Task i need to accomplish :
=================
I have to read ACCESS tables and EXCEL sheets to convert in to XML file so that i can store that values in SQL SERVER using JOnAS Application Server .

Here's my story which will tell what i need :
===========================

I created SESSION BEAN program which contains function which will convert ACCESS/EXCEL file in to XML .

I also created ENTITY BEAN program which contains function to store the data in SQL SERVER(the data which are obtained from that XML file).

i have developed that ENTITY module in such a way that i need to pass the data as arguments of create method of that ENTITY BEAN as follows .


Java Syntax (Toggle Plain Text)
  1. public String ejbCreate(String empid, String firstname, String lastname, String circle, String subcircle, String created_date, String updated_date) throws CreateException {
  2. try{
  3. insertRow(empid,firstname,lastname,circle,subcircle,created_date,updated_date);
  4. }catch(SQLException ex){
  5. throw new EJBException("ejbCreate: " + ex.getMessage());
  6. }
  7. this.empid = empid;
  8. this.firstName = firstname;
  9. this.lastName = lastname;
  10. this.Circle = circle;
  11. this.Subcircle=subcircle;
  12. this.Created_Date=created_date;
  13. this.Updated_Date=updated_date;
  14. return empid;
  15.  
  16. }
  17.  
  18. private void insertRow(String empid, String firstName,
  19. String lastName, String Circle,String Subcirle,String Created_Date,String Updated_Date) throws SQLException{
  20. makeConnection();
  21. String insertStatement = "insert into Employee values ( ? , ? , ? , ?,?, ?,? )";
  22. PreparedStatement prepStmt = con.prepareStatement(insertStatement);
  23.  
  24. prepStmt.setString(1, empid);
  25. prepStmt.setString(2, firstName);
  26. prepStmt.setString(3, lastName);
  27. prepStmt.setString(4, Circle);
  28. prepStmt.setString(5, Subcircle);
  29. prepStmt.setString(6,Created_Date);
  30. prepStmt.setString(7,Updated_Date);
  31.  
  32.  
  33. prepStmt.executeUpdate();
  34. prepStmt.close();
  35. releaseConnection();
  36. }
What i planned to fetch XML data:
=====================

I will develop a function to parse XML file in that SESSION BEAN ( which created that XML file) to obtain that data and i have to pass that values to the above function which is in ENTITY BEAN.

I came to know that i can't invoke create method of ENTITY bean so i need to invoke that insertRow function directly (which actually stores data in SQL SERVER) .

So please guide me HOW CAN I INVOKE a ENTITY BEAN method (insertRow) from an SESSION BEAN with sample coding .

I think it's quite a big story .Thanks for your patience

Thanks in advance.
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
parthiban is offline Offline
80 posts
since Sep 2006
Mar 28th, 2007
0

Re: How to call a EJB method from Session bean method

You do NEVER call those methods directly, how often do I have to repeat that?

In fact, if you don't understand that you can't even call a private method from another class (or even another instance of the same class) you should not be doing any J2EE stuff AT ALL but start with an introductory tutorial on Java.

You should also do some introductory tutorial on EJBs after that, and one that handles MODERN EJBs, as directly doing JDBC access from entity beans is NOT the way to do things, and hasn't been for years.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 30th, 2007
0

Re: How to call a EJB method from Session bean method

Hi Jwenting ,
Sorry for such a silly question .

Thanks
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
parthiban is offline Offline
80 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Installing JOpenGL
Next Thread in Java Forum Timeline: Detect KeyPress From Console?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC