This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Data Access Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Data Access Object" Watch "Data Access Object" New topic

Data Access Object

bhumireddy reddy

Joined: Jun 17, 2006
Posts: 1
Hi to all,

Can any one help me by giving the DAO example code. and let me know the process of dao.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29287

Welcome to JavaRanch!

Have you seen Sun's DAO description page yet? It has a good description and example.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ravi bhosale

Joined: Jun 17, 2006
Posts: 5
Hi following code shows abstraction between business layer and data access layer. data access can be any like using JDBC or Hibernate.

The DAO Factory
public abstract class DAOFactory
public static final DAOFactory HIBERNATE =
new com.vmware.vcp.dao.hibernate.HibernateDAOFactory();

public static final DAOFactory JDBC =
new com.vmware.vcp.dao.jdbc.JDBCDAOFactory();

public static final DAOFactory DEFAULT = HIBERNATE;
public static final DAOFactory getDAOFactory()
return DEFAULT;

public abstract CustomerDAO getCustomerDAO();

The Hibernate DAO Factory
public class HibernateDAOFactory extends DAOFactory
public CustomerDAO getCustomerDAO()
return new CustomerDAOHibernate(getCurrentSession(Constants.Hibernate.MASTER_SESSION_FACTORY_NAME));

The Customer DAO interface
public interface CustomerDAO {
public Customer findCustomerForUserId(String id, boolean lock);

The concrete impl of customer dao
public class CustomerDAOHibernate implements CustomerDAO
public Customer findCustomerForUserId(String id, boolean lock)
// Database access code

Business layer code

DAOFactory df = DAOFactory.getDAOFactory();
CustomerDAO custDao = df.getCustomerDAO();
custDao.findCustomerForUserId(UserId, true);
I agree. Here's the link:
subject: Data Access Object
Similar Threads
FireStorm/DAO ver 2.2 download link?
Cross-database and cross-schema portability
Spring extrange behaiuvour
regarding DAO