aspose file tools*
The moose likes JSP and the fly likes JavaBean Connect to Database, Which should return? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JavaBean Connect to Database, Which should return? " Watch "JavaBean Connect to Database, Which should return? " New topic
Author

JavaBean Connect to Database, Which should return?

xie yufei
Greenhorn

Joined: Dec 26, 2005
Posts: 19
Commonly, we use JavaBean to connect to database in Jsp, What should return to the Jsp? Some one say the "ResultSet", and others say use ArrayList, I am confused. The examples:
1、return ResultSet

2、return ArraList
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think that we usually return an ArrayList, BUT:
I don't think that it is a good idea to launch a query for each call.
Usually, we only have

where users is a member variable. You should make a DB call only once, before displaying the JSP.


[My Blog]
All roads lead to JavaRanch
xie yufei
Greenhorn

Joined: Dec 26, 2005
Posts: 19
where users is a member variable. You should make a DB call only once, before displaying the JSP.


Satou kurinosuke, thanks a lot for your kindness!
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
The best practice is to write your own Data Access Object (DAO class/ look for DAO pattern). Your DAO class is responsible for accessing the data from the database and map the ResultSet to JavaBean(s) and return a Collection (i.e List, Set, Map etc) of JavaBeans or a single JavaBean.

Note: If you have heard of a O-R(Object to Relational mapping) framework called Hibernate that is what it does. Still you need to use a DAO.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
xie yufei
Greenhorn

Joined: Dec 26, 2005
Posts: 19
Arulkumaran Kumaraswamipillai, thank you very much!

Though what you say is difficult for me, I still can learn more fresh knowlege from you words.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBean Connect to Database, Which should return?