• Post Reply Bookmark Topic Watch Topic
  • New Topic

question on MVC  RSS feed

 
Ram Kas
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In MVC Architecture, as far as my understanding goes, View is JSP, Controller is Servlet and Model is a Bean.

Suppose, if I enter some data in a text box(of view), it is validated in controller(servlet), and inserted in a Java Bean. So, How are the values in a bean go to DB. Do we have one more layer of JDBC there? or is JDBC code is handled in bean itself?

Any comments on this is highly appreciated.

Thanks,
Dinakar.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dinakar Kasturi:
Do we have one more layer of JDBC there? or is JDBC code is handled in bean itself?


Yes, generally JavaBeans use JDBC or ORM (like Hibernate) to delegate with Database.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chetan Parekh:

Yes, generally JavaBeans use JDBC or ORM (like Hibernate) to delegate with Database.


Not necessarily. Beans are frequently just transport objects that hold the data to be taken a model layer of business code that performs the business logic. Frequently the persistence layer that deals with the DB is even a lower layer than the business logic.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either way is valid.

For larger projects there is certainly merit in separating your data access code from the rest of the app.

A simple rule of thumb that has worked well for me is:
Never import both javax.servlet.* and java.sql.* in the same class.

Make sure all of your bean's methods can be called from a main method on the command line (or from a test script) without a servlet container and make sure that your servlets and JSPs have absolutely no idea how your beans are getting or writing the data.
 
Ram Kas
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your valuable comments.

Dinakar Kasturi
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!