EJB design: EJB vs JDBC

  1. EJB vs JDBC (2 messages)

    Given an application which requires a lot of database calls, which of JDBC or EJB would be faster, and how to choose one technology over the other?

    Threaded Messages (2)

  2. EJB vs JDBC[ Go to top ]

    They are not competing technologies. EJB is for encapsulating business logic and making it available to remote clients without bundling the code on the client. It also provides transaction features, etc.

    JDBC is just for accessing SQL datbases. One would typically write JDBC code inside an EJB. If your clients have direct access to the database, doing JDBC inside EJB would be technically slower (since clients connect to EJBs, which connect to the DB vs. clients just connecting to DB), but that kind of architecture is basically just Client/Server and has many well-documented issues. Additionally, the database calls will probably be the largest part of the transaction time, so the addition of EJB remote calls won't hurt you that much.

    The preferred way is to create EJBs for the business processes you need to implement, and your client calls methods on said EJBs. Your EJBs then make the necessary JDBC calls.

  3. EJB vs JDBC[ Go to top ]

    Using EJB or JDBC can be applied on a case-to-case basis. Typical Client-Server Apps do not really need a middleware with heavy weight EJB Components. They could be much more faster with a direct JDBC call to the Database. Apps really planning to go for a Three-tier architecture can choose to include a business layer using EJB components. Personally in my projects using EJBs have benefitted applications have separation of layers making it much more maintainable in the future.