| | |
How to call a EJB method from Session bean method
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
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.
•
•
•
•
You don't.
You create a new entity, and it takes care of its database access itself.
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)
public String ejbCreate(String empid, String firstname, String lastname, String circle, String subcircle, String created_date, String updated_date) throws CreateException { try{ insertRow(empid,firstname,lastname,circle,subcircle,created_date,updated_date); }catch(SQLException ex){ throw new EJBException("ejbCreate: " + ex.getMessage()); } this.empid = empid; this.firstName = firstname; this.lastName = lastname; this.Circle = circle; this.Subcircle=subcircle; this.Created_Date=created_date; this.Updated_Date=updated_date; return empid; } private void insertRow(String empid, String firstName, String lastName, String Circle,String Subcirle,String Created_Date,String Updated_Date) throws SQLException{ makeConnection(); String insertStatement = "insert into Employee values ( ? , ? , ? , ?,?, ?,? )"; PreparedStatement prepStmt = con.prepareStatement(insertStatement); prepStmt.setString(1, empid); prepStmt.setString(2, firstName); prepStmt.setString(3, lastName); prepStmt.setString(4, Circle); prepStmt.setString(5, Subcircle); prepStmt.setString(6,Created_Date); prepStmt.setString(7,Updated_Date); prepStmt.executeUpdate(); prepStmt.close(); releaseConnection(); }
=====================
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.
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- Stopping a very time consuming class method's execution on tomcat server using JSP. (JSP)
- Java Tutorials (Java)
- Generic method parser / invoker (C#)
- Problem in running a simple session bean in JOnAS (Java)
- How can i call my FileOutput method to output the array ?? really confused... (Java)
Other Threads in the Java Forum
- Previous Thread: Why is the main method static?
- Next Thread: Detect KeyPress From Console?
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






