Hi,

I have a simple question - what is the best way of getting the data from
dataabse and display them.

Let's have an example - I have in the database 100 records (lines) in one
table and I want to display them as one <table></table> in HTML page. I do
it this way -

1. in jspInit() I create a Connection pool.
2. I create class (MyUser) in which I will save data from database. 1
instance of that class will represent on line in the database.
3. In body of the JSP page I get connection from the pool.
4. In the body, before I print any html tags, I read everything from that
table (100 records), creating MyUser object for each line and adding it to
Vector class (in while cycle) like this example
-----------
... here will be some select ....
 Vector temp_user = new Vector();
  while(UserR.next())  // UserR is the ResultSet
  {
     temp_user.add(new
MyUser(UserR.getString("user.id"),UserR.getString("user.name")));
  }
-----------
5. I return connection back to the pool. I thing, that it is important to
return connection to it pool as soon as possible.
6. Finally I print a HTML table with other html stuff
-----------
 Enumeration obsah = temp_user.elements();
 while(obsah.hasMoreElements())
 {
     MyUser muser = (MyUser) obsah.nextElement();
    out.println(myuser.getID() + " " + muser.getName()+" some html stuff ");
{
-----------

Another way how to do this could be printing  data in the first while cycle,
but then I will be connected to the database for longer time.

What it your way (probably better) how do you do this ?

Thnaks a lot
Tomas Zeman

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to