Session Bean accessing JDBC

Discussions

EJB programming & troubleshooting: Session Bean accessing JDBC

  1. Session Bean accessing JDBC (6 messages)

    I would like to know if a session bean can access the database via JDBC. If so, how do I get the connection?

    Thanks

    Threaded Messages (6)

  2. Session Bean accessing JDBC[ Go to top ]

    Yes, a session EJB can access a database through JDBC.
    The usual way to implement this is using a DataSource, in order to delegate pool management and etcetera to the apps server.
    How to configure a DataSource, depends on your app server. In Weblogic you must define connection pools and DataSources using them. In JBoss you must write a descriptor and deploy it the same way you deploy an EAR.
    Hope it helps.

    Regards,
    Martin
  3. Data Access Objects[ Go to top ]

    I think you should look at the Data Access Object Core J2EE Pattern


    Background information is here:

    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html

    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html


    When you're ready to start producing DAO code, you might prefer to generate it rather than write by hand.

    FireStorm/DAO Java code generator imports database schema definitions from from live databases via JDBC and then generates a complete persistence tier based on the Data Access Object design pattern

    http://www.codefutures.com/dao/


    PJ Murray
    CodeFutures - Java Code Generation
    http://www.codefutures.com
  4. Session Bean accessing JDBC[ Go to top ]

    A session bean can access database via JDBC,but it is better not to include the data access code in SessionBean.
    It can be implemented in other data access objects.This way your session bean remains independent of data access mechanism.
  5. Session Bean accessing JDBC[ Go to top ]

    Agree... missed that one ;)
    It's a usual solution we know as "Data Access Object" (aka DAO)

    Regards,
    Martin
  6. Session Bean accessing JDBC[ Go to top ]

    There is no reason your logical DAO cant be a Stateless Session Bean. At least you get the instance pooling advantage.

    Of course logically you want to seperate data access from business rules, but dont confuse logical design with physical implementation.

    Dave Wolf
    Cynergy Systems
    Cynergy Systems
  7. DAO as SLSBs[ Go to top ]

    There is no reason your logical DAO cant be a Stateless Session Bean. At least you get the instance pooling advantage.Of course logically you want to seperate data access from business rules, but dont confuse logical design with physical implementation.Dave WolfCynergy SystemsCynergy Systems

    It will be interesting to hear from architects who have taken this route. Does the instance pooling offer much of a help in case of DAOs, quantitatively speaking. Would the Romans, Johnsons, Tates, Fowlers and Sumitros approve of this approach?