• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Stored Procedures from EJB

 
Jack, jill
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can U please tell me how to call stored procedures from EJB.
If so , which bean is suitable for this
Do reply
Thanks in advance
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you mean stored procedures in a database, and you have a JDBC driver that supports the calling of stored procedures you could do it from within a BMP EJB. For example:
<CODE>String sql = "{call proc_squareInt(?, ?)}";
CallableStatement cstmt1 = conn.prepareCall(sql);
// Register out parameters
cstmt1.registerOutParameter(2, java.sql.Types.INTEGER);
for (int i = 0; i </CODE>... etc
could be placed within your bean. There's no reason why you shouldn't use stored procedures within your EJB, but personally, I don't like the idea of stored procedures. They mix data access together with logic which should IMO be separated. If you're going to use component-based technologies such as EJBs shouldn't you consider the n-tier architecture?
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah... one other thing, your name doesn't fit with the JavaRanch naming policy. Would you have a look at that please?
Thanks.
 
Venkat Ammisetty
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jill
Calling a storedProcedure from EJB is same as in your normal Java program.
But it is not an ideal solution,you pass a parameter to that method to call that StoredProcedure.
By doing this you can use your Bean for any storedProcedure not only to that perticular StoredProcedure.
If you put your storedProcedure in a method directly in a Bean,that method is only usefull to that storedProcedure only.
If you pass parameters,you can enjoy more flexibilty by calling your storedProcedure from client Program i.e JSP or Server or Applet.
This is only my suggestion.
If your requirement is not sutable my idea leave it.
Bye
Venkat
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!