DAO design pattern is used in the data persistent layer of a Java
application. It mainly uses OOPS principle of Encapsulation.
By using DAO pattern it makes the application loosely coupled and
less dependent on actual database.
We can even implement some in-memory database like H2 with
DAO to handle the unit-testing.
In short, DAO hides the underlying database implementation from
the class that accesses the data via DAO object.
Recently we can combine DAO with Spring framework to inject any
DB implementation.
xxxxxxxxxx
public class AccessBook {
public static void main(String[] args) {
BookDao bookDao = new BookDaoImpl();
for (Books book : bookDao.getAllBooks()) {
System.out.println("Book ISBN : " + book.getIsbn());
}
//update student
Books book = bookDao.getAllBooks().get(1);
book.setBookName("Algorithms");
bookDao.saveBook(book);
}
}
https://www.digitalocean.com/community/tutorials/dao-design-pattern