Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

question on MVC

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your valuable comments.

Dinakar Kasturi
reply
    Bookmark Topic Watch Topic
  • New Topic