File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Using Bean, DAO with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using Bean, DAO with JSP" Watch "Using Bean, DAO with JSP" New topic

Using Bean, DAO with JSP

Anubhav Singhal

Joined: Jan 30, 2013
Posts: 4
Hi, I am new to jsp. I am familiar with simple jsp development using mysql and tomcat. But i want to learn how can i use Bean, DAO with jsp so that i will more like MVC. I searched on internet but i didn't find any good samples to startup. I would really appreciate if somebody can help me out with a simple demo code to demonstrate how these all work together.

Assuming MySQL Database "test" with table structure as follows:

table1: login
columns: uid int,
username varchar(25),
password varchar(25),
name varchar(30).

table2: users
columns: fname varchar(15),
lname varchar(15),
age int,
email varchar(50),
phone varchar(15).

Awaiting for a good reply.
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
My suggestion: Make a start, present what you have done and we can critique.

Most obvious thing to do would be to create some Java classes representing the objects you want.
They may or may not be a one to one mapping with the database tables.

Then write your DAO.
Most of the time with a DAO you want CRUD: Create, Read, Update, Delete. And potentially also a "List" operation.
For instance that might include a class "UserDAO" with method "saveUser(User user)". Said method takes your user object and saves it to the database.

Your JSP should only use your beans, and have no database queries/code

Questions to ask yourself:
How do these two tables login and users relate to one another?
What is the use case? Will that affect how we access the data?

I agree. Here's the link:
subject: Using Bean, DAO with JSP
It's not a secret anymore!