Contact:   Tel: 2726  -  New Media Systems, 1st Floor South, Queens Walk


Tomas,

With XML/XSL so hot in the market right now, I would suggest you look at this
alternative.


The implementation of XML/XSL will be like this:

   Write a class to extract the data from the database and produce an XML
   representation as a string;
   Write a XSL that will transform your XML into HTML of your design. You only
   need to design and write this XSL once and store it as a static resource on
   your server;
   Use LotusXSL or Cocoon to generate the HTML

The advantage of this solution is that your codes will be reusable for any other
applications that take XML as input, which could be the case for many future
applications. For references of doing the above steps, checkout
'http://www.ibiblio.org/xml/books/bible/updates/14.html' for the step 2, and '
http://www.mulberrytech.com/xsl/xsl-list/archive/msg08166.html' for the step 3


Personally I found this was a very enjoyable programming experience. It however
still keeps you in servlet business as you would still use the servlet as entry
point.


Cheers,


Charles






Tomas Zeman <[EMAIL PROTECTED]> on 11/09/2000 02:49:27 PM

To:        [EMAIL PROTECTED]
cc:         (bcc: Charles Chen/YellowPages)
From:      Tomas Zeman <[EMAIL PROTECTED]>, 9 November 2000, 2:49 p.m.

Servlet design (getting stuff from DB)  [Scanned by Yellow Pages PostMaster]


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

___________________________________________________________________________
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