Skip to main content

DAO (Data Access Object) Pattern

Learn DAO (Data Access Object) Pattern (Data Access Patterns, Enterprise Design Patterns) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

What is the DAO Pattern? A Data Access Object (DAO) abstracts and encapsulates all access to a data source (a database, a file, a web service) behind a well-defined interface. The rest of the application talks to the DAO's interface only - it never writes SQL or touches a Connection object directly. • Keeps persistence-specific code (JDBC, SQL) isolated in one layer. • If the storage technology changes (JDBC -> JPA, MySQL -> PostgreSQL), only the DAO implementation changes - callers are untouched. • Makes unit testing easier - a service can be tested against a fake/mock DAO without hitting a...

More lessons in Data Access Patterns