• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

EJB vs JDBC

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 28140
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC will usually be faster, but harder to maintain. EJBs are good for cases where having a prewritten (and pre-debugged!) system that caches and does transaction management is important.
I generally program flexible first, then measure and tune where needed. I learned a long time ago that the places where you "know" performance is an issue are almost never the places where it actually is. As has been said before - it's easier to speed up a clean design than to unsnarl an "efficient" one that doesn't work.
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's quite hard to compare that way. Afterall, the underlying pipelines of Entity Beans are using JDBC calls, right?
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rahul,
It depends upon the architecture which one is implementing.If you want the services of transaction management, security, and connection pooling ,OR/mapping available then u go for entity beans wherein these features are provided by your application server, whereas if you want to only acess database tables where the data accessed is not tht frequent and u need not have to take care of synchronization issues u can use plain JDBC calls.
Mind you u can use JDBC with JTA to programm whatever the EJB container gives u..so the decision boils down to how complex and big is your transactions.
Rishi
SCJP,SCWCD
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would put it like this:
EJB container provides services like declarative transaction, security etc. This makes application development easy. EJB Container also maintains a pool of beans to service multiple clients. An instance is taken out of the pool when a client sends a request. There is no need to initialize the bean with any information. When the application user base is large, this helps tremendously. But internaly EJBs make use of JDBC calls to access databases.
So the answer of your question: if your application is making lot of database calls, with small application user base and non EJB experienced developers, go for JDBC. Else go for EJB.
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go with EJBs depending on the app server u are using.
Please give a reading of Core J2EE patterns book to decide by yourself.
But as a long term solution it is preferred to use EJB in combination with JDBC(inside EJB u have the data access layer which uses JDBC).
Kishore.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
I guess jdbc would be real fast and if you do have a situation where u query or insert into multiple tables jdbc i guess would be the best to use . As said earlier you could use jdbc with jta for transaction management. Well the major performance issue would be ideally if u had a query of more than one table then u gotto have many ejb's each for a table in the database ,and the more ejb's u have the lookup from your session bean would be more costly.Sope i would suggest you go for jdbc though ou would not get the sturdiness , maintenance and security you get with EJB
regards
riaz
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you go with Entity EJB's and CMP, you don't do the SQL (in an IDE). If you go with JDBC, you may need to write SQL that is not portable from DB to DB.

Just an extra 2 cents.
-Randy
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic