How to write code in Java Beans for accessing databases in case of MVC?
See the JDBC tutorial track of the Java tutorial. When you master that, look at things like JPA and Hibernate as nicer ways to abstract away the raw database access code.