This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes MVC or DAO? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MVC or DAO?" Watch "MVC or DAO?" New topic
Author

MVC or DAO?

Akhil kumarS
Greenhorn

Joined: Oct 16, 2007
Posts: 13
Hi Friends,
I would like to know Which design pattern is better?MVC or DAO...What is there major difference? Which architecture uses stored procedures more?Is it better to implement business logic in SPs?
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Is MVC better than DAO ... this is like asking whether gloves are better than shoes, they serve different purposes. Do you have some application in mind? If so, then you can do some investigation of your own and come back to this forum with some specific questions.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Originally posted by Akhil kumarS:
Hi Friends,
I would like to know Which design pattern is better?MVC or DAO...What is there major difference?

As Roger said, they do different things. MVC is a front end pattern and DAO is a back end pattern.

Which architecture uses stored procedures more?

Most architectures are agnostic once they get to the database technology. Your DAO could have a stored proc, Spring, Hibernate, plain JDBC, etc. The DAO isolates the rest of the code from this design decision.

Is it better to implement business logic in SPs?

It's not inherently better. Some would argue it is better; some would argue it is worse. I think it depends on the specific situation and who is calling the code.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Venkatraman Kandaswamy
Ranch Hand

Joined: Jul 07, 2004
Posts: 120
I personally prefer keeping business logic in code - and keep most of the business logic out of the Stored procedure - because maintenance becomes hard and its difficult to test - unit wise.

Now when will I use a stored procedure? - to improve performance. Also lets say I have to update a value for a particular set of customers - and in a case of a million records doing it using stored procedure makes lot of sense.
[ February 15, 2008: Message edited by: Venkatraman Kandaswamy ]

--Venkatraman<br />SCJP 1.4<br /><a href="http://kvrlogs.blogspot.com" target="_blank" rel="nofollow">blog</a>
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Originally posted by Venkatraman Kandaswamy:
I personally prefer keeping business logic in code - and keep most of the business logic out of the Stored procedure - because ...

On most of the projects I work on we have something to do with a database. I've worked on projects where we used the database purely to store data, and where we had all business logic in Java code. I've also worked on projects where there was a separate team of database experts who designed and maintained the database. We were only allowed to access the database via stored procedure calls (we were not allowed to do queries, updates and inserts directly), so that the database people could control the access to the database and check integrity of the data in their stored procedures.

So, sometimes one approach works well, other times another approach.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ed Carrington
Ranch Hand

Joined: Oct 11, 2007
Posts: 77
What is the difference between Stored Procedure and Prepared Statement?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

>>What is there major difference?

I see MVC as how you design your application. A DAO is the proper way to have your application access your data, or persist the state of your application to the database. I often use the term MVCD, to emphasise how data access can be thought of a fourth, separate but important part of application development.

>>Which architecture uses stored procedures more?

Depends on how you implement it. A good DAO pattern allows implementations to be switched in and out seamlessly. With a good DAO pattern, the answer to 'which data access strategy should we use?' becomes "who cares".

-Cameron McKenzie
 
Consider Paul's rocket mass heater.
 
subject: MVC or DAO?
 
Similar Threads
PAC x MVC
flow from JSP to DB
DAO or JDO-like persistance?
Basic Bean Doubt
PAC x MVC