A follow up to the J2EE DAO Pattern:  I found that it helps a lot using
externalized SQL statements, i.e., build SQL statements in an XML file with your
own DTD.  It's point #3 in that blueprint.  However, to this date I haven't
found any good examples online.  Also I sent an email to the blueprint team
asking how to pass multiple arguments(for example, a collection.)  If anyone
looked at the 'petsstore' example that comes with the blueprints, you would
notice that the number of parameters are hardcoded all the time in the Dao
related .xml files.  So still I don't know how to pass a collection as the
'input-mapping.'  

I am just wondering if anyone is using externalized SQL statements in their
application as well. What's your view on it?  

Thanks!

-----Original Message-----
From: Sloan Bowman [mailto:[EMAIL PROTECTED] 
Sent: June 18, 2003 9:49 PM
To: Struts Users Mailing List
Subject: Re: Struts and database


        I will do my best to explain this but I will also point you 
in the right direction. First off you need to read the Java 
Blueprints on using DAO with J2ee. This will teach you the best 
methods of using Databases by using the DAO to encapsulate the 
DataSource . Here is the link to the Java Blueprints 
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html 
read this complete document and it will help you out alot with how 
you should use your databases in your applications.
        Lets use an example say for a User requesting a item from the 
online store for our example. First you build the ActionForm which 
stores the data sent by the form. The ActionForm is passed through 
the FrontController which in turn dispatches you to the correct 
Action. In our case the Action will be using methods from a class 
which contains all of your Buisness logic.  Form example, we have a 
ItemDAO which has a method getItem(int itemNum). This method returns 
a ItemBean which stores all of the information about that item. This 
Bean you are using to store all of the information is called a State 
Bean (if I remember right, corrections are welcome). When you get the 
ItemBean returned from the method getItem(int itemNum) you can then 
add it to your session/request etc.. for example you could do 
request.setAttribute("itemBean", itemBean). Now once you return the 
ActionForward in the Action (Example: mapping.findForward("success")) 
the itemBean will be part of the request and you acn access these 
properties in the View using jsp, velocity etc.. I hope this helps 
you out.

--Sloan

p.s. Sorry for the type o's I didn't proof read


>Hi! Would anyone give me some examples of database programming, which
>lead from retrieving data to rendering view. (I mean real database, not
>from XML files), e.g. any web site with source, or even better, some
>simple example?  I am very confused on how to use beans from the model.
>If there any book that focus on database programming?  I have been
>searching on the web, but unable to find.
>
>Andy Cheng
>[EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to