Question on accessing database in Session Bean


EJB programming & troubleshooting: Question on accessing database in Session Bean

  1. Question on accessing database in Session Bean (5 messages)

    Hi all,

    I've read the J2EE tutorial about opening database connection through the session bean which says that it must be done through resource reference, but I find it very complex to do so (hey, I'm an EJB newbie here), is this the only way to do it? Can I open connection without the resource reference ? What's the downside of each alternative?

    Suggestion and Code snippet would be greatly appreciated.

    Thanks in advance

  2. The whole point in using the resource reference is the flexibility brought by the extra indirection.

    It is admittedly more difficult to use the resource reference when the alternative is to use the familiar JDBC API stuff, but when using a resource reference, you can configure the datasources easily at deployment time (or on-the-fly if your appserver supports it).

    You should anyway configure a datasource/connection pool instead making database connections yourself in the code. Then you're already halfway there...

    Check your appserver's documentation. There should be an example of the necessary mappings and code.
  3. Thanks for the response,

    Could u point tutorials about this resource reference for begginers ?

  4. I'd suggest you read the free e-book, Mastering EJB II, available right here at TSS ( It's a good source for EJB related information.
  5. Another new bie question. What is a resource reference. Where can I find some material/explanation regarding that? Is it different from a DataSource?
  6. A DataSource is a resource reference. See: