wood burning stoves 2.0*
The moose likes Servlets and the fly likes MVS Problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "MVS Problem?" Watch "MVS Problem?" New topic
Author

MVS Problem?

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
Hi all,

I am learning JSP and Servlets. I am trying to do a small project in the area I have learned so far. Simply I am trying to do a MVC thing.

I am just adding/deleting/updating the customer registration details to the Database.
Now the section I havint the doubt.
I am using JSP for view that is, I am creating the form in the Customer.jsp (for example: Customer ID(int), Customer Name(char), Customer Age(int), Customer DOB(date))

I am using JavaBean for setting and getting the properties in Customer.java. (for example:
private String customer_id,customer_name,customer_age and customer_dob;
And getter and setter method.


Now whether the database connection and all other updating thing to the database should be kept at Servlets (i.e., Customer_Ser.java) or at JavaBean(i.e., Customer.java)

I have seen the database connection in JSP, Servlet and Javabean. I know it is very bad thing to do any database thing in JSP. But, which one is best to use the database connection ? in Servlet or Java (Javabean).

Is there any situation to use the database connection in JSP.

If possible, any sample coding(I have written the coding, but I want to know, which one is having better performance and also see how the real appln have coded in the MVC) for just adding the details to the database in MVC Pattern.

Thanks in advance,
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
If you are following the MVC pattern, the DB connaction should definitely not be in the JSP or servlet. Usually, that will be part of the model/business logic. Enterprise level applications would even separate it further by putting it in it�s own class using the DAO pattern.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
No servlet, no javabean, for database connection use separate class(classes). Maybe take a look at some DB related patterns as DAO for example.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
thanks for your reply.

So I can say that JSP only for view that is for presentation like GUI(forms).
Servlets for controller.
And what about JavaBeans? it is only for Property only?
can i get any sample codings or example in website for Model-View-Controller
Even JavaBean also a Java file with some speical properties. Why you are telling not to use database connection in JavaBean.

If I am using separated class for database connection, what will be the use. In that case for example, for registration of the customer details in the database requires the following files. (pls, at this moment EJB is far away from my learning)

Customer.jsp - For Forms
Customer_JavaBean.java- For getting and setting properties
Customer_Servlet.java - For controlling?(Having doubt in this file of his
role
Customer_DB.java - For database connection

How these four will interact. I want the example thing for the above mentioned thing. If possible, pls provide the link. I had searched in google, but I am getting some complex mvc with EJB.

Also suggest, the above four files are mandatory for fulfilling a Good MVC Pattern.
Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129
Can I get the sample or example codings in the DAO Pattern. I have searched in google. Not getting any useful/related to my problem. Just I want to add the customer/student details in the database by using MVS, or as the group member told as DAO. How to use it, any sample or example coding will be available.
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html


Cheers!<br /><b>Annie</b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVS Problem?
 
Similar Threads
Uploading Flat file in the database
Keeping connection to a DB with Servlets JavaBeans
mvc - links, tutorials
DAO Pattern & Head First Series
codofobia