This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to code client of DAO?  RSS feed

 
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying my hand at using the DAO pattern but I doubt if I'm using it as it is meant. For the time being I'm calling the JDBC implementation (which is all that I'm going to need at this point).

Is retrieving the data in the main method for serious use case a good thing? I was reading old posts and a bottom post showed using the DAO with the help of dependency injection? I've never used dependency injection and would like to know how it would come in handy here.

Do let me know your thoughts and how could I improve my code.

Here is the code getting the data from the persistent store,

 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dependency injection would remove the dependency between your client class and the JdbcCustomerInfoDao class. So all the client knows would be CustomerInfoDao which would typically be an interface.
Dependency injection however requires some libraries that implement it to be available in your client environment. Popular ones are CDI , Spring and Google's Guice.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response. It definitely helps me in getting started with DI.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!