Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Bean, DAO with JSP

 
Anubhav Singhal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1720
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic