Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
Woohoo!!! 

But you'll have to forgive my ignorance, but any chance of a more ostensive
answer, like an example for example..

So something like 

DataSource ds = getDatasource("mykey");

(MyBEan).doSomething(ds, and other args);

Is this along the right lines?

Many thanks

mark

On 17-12-2002 15:05, "Matthias Bauer" <[EMAIL PROTECTED]> wrote:

> The normal thing to is the following: You aquire a database connection
> in the action class and pass it on as a parameter to the bean's database
> methods.
> 
> --- Matthias
> 
> Mark wrote:
> 
>> Sorry to repost this question, but the more i think about it the more i
>> think it a reasonable one (please tell me if i'm wrong).
>> 
>> 
>> -- Forwarded Message
>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>> Subject: dataSources outside of actionservlet
>> 
>> hello
>> 
>> you'll all have to forgive my stupidity but i've been having real problems
>> trying to reference the datasource specified in config.xml in my business
>> logic classes.
>> 
>> I've been very good and seperated everything as one should. but i really
>> need a straight answer to this (i.e. an example that works).
>> 
>> "For maximum code re-use, business logic beans should be designed and
>> implemented so that they do not know they are being executed in a web
>> application environment"
>> 
>> now i've only seen examples referencing the datasource inside an action
>> servlet, this appears to go against the design pattern. So how do i do this?
>> have i neglected to find the correct example? why are all the examples of
>> how to reference the datasource breaking the aforementioned priciple? please
>> i'm very confused ..
>> 
>> many thanks in advance
>> 
>> mark
>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> 
>> For additional commands, e-mail:
>> 
>> 
>> 
>> 
>> -- End of Forwarded Message
>> 
>> 
>> --
>> To unsubscribe, e-mail:   
>> For additional commands, e-mail: 
>> 
>>  
>> 
> 
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 
> 


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
Thanks keith that looks like a really good elegant way of doing this, but as
i conceded before I particularly stupid, and i don't get it. To be honest
I've always had the db pooling stuff taken care for me before which was only
of the attractions of using struts..

Is there no means to referencing to setting in config.xml. Like  an example
that explains the following

Stuff_to_get_to_the_stuff_configxml.getDatasource(mykey);

Or am i trying to make my life too simple and really should give up
development and become a dustman or something?

Many thanks again mark


On 17-12-2002 15:12, "keithBacon" <[EMAIL PROTECTED]> wrote:

> Using the command design pattern you can ensure the DB code needs to be coded
> only once.
> See the example below
> 
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg24579.html
> 
> 
> --- Matthias Bauer <[EMAIL PROTECTED]> wrote:
>> The normal thing to is the following: You aquire a database connection
>> in the action class and pass it on as a parameter to the bean's database
>> methods.
>> 
>> --- Matthias
>> 
>> Mark wrote:
>> 
>>> Sorry to repost this question, but the more i think about it the more i
>>> think it a reasonable one (please tell me if i'm wrong).
>>> 
>>> 
>>> -- Forwarded Message
>>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>>> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>>> Subject: dataSources outside of actionservlet
>>> 
>>> hello
>>> 
>>> you'll all have to forgive my stupidity but i've been having real problems
>>> trying to reference the datasource specified in config.xml in my business
>>> logic classes.
>>> 
>>> I've been very good and seperated everything as one should. but i really
>>> need a straight answer to this (i.e. an example that works).
>>> 
>>> "For maximum code re-use, business logic beans should be designed and
>>> implemented so that they do not know they are being executed in a web
>>> application environment"
>>> 
>>> now i've only seen examples referencing the datasource inside an action
>>> servlet, this appears to go against the design pattern. So how do i do this?
>>> have i neglected to find the correct example? why are all the examples of
>>> how to reference the datasource breaking the aforementioned priciple? please
>>> i'm very confused ..
>>> 
>>> many thanks in advance
>>> 
>>> mark
>>> 
>>> 
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> 
>>> For additional commands, e-mail:
>>> 
>>> 
>>> 
>>> 
>>> -- End of Forwarded Message
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> 
>>> For additional commands, e-mail:
>> 
>>> 
>>>  
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:   
>> For additional commands, e-mail: 
>> 
> 
> 
> =
> ~~
> Search the archive:-
> http://www.mail-archive.com/struts-user%40jakarta.apache.org/
> ~~
> Keith Bacon - Looking for struts work - South-East UK.
> phone UK 07960 011275
> 
> __
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 
> 


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
I know that , i've read that .. But I what i really want to know is this

Without importing any servlet stuff

Some_means_of_getting_to_details_in_config_xml.getDatasource(mykey);

Many thanks mark

On 17-12-2002 15:17, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:

> Another option is to aquire the database connection via jndi when you
> need it.
> 
> Edgar
> 
> -Original Message-
> From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 9:05 AM
> To: 'Struts Users Mailing List'
> Subject: Re: FW: dataSources outside of actionservlet
> 
> 
> The normal thing to is the following: You aquire a database connection
> in the action class and pass it on as a parameter to the bean's database
> 
> methods.
> 
> --- Matthias
> 
> Mark wrote:
> 
>> Sorry to repost this question, but the more i think about it the more i
> 
>> think it a reasonable one (please tell me if i'm wrong).
>> 
>> 
>> -- Forwarded Message
>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>> Subject: dataSources outside of actionservlet
>> 
>> hello
>> 
>> you'll all have to forgive my stupidity but i've been having real
>> problems trying to reference the datasource specified in config.xml in
>> my business logic classes.
>> 
>> I've been very good and seperated everything as one should. but i
>> really need a straight answer to this (i.e. an example that works).
>> 
>> "For maximum code re-use, business logic beans should be designed and
>> implemented so that they do not know they are being executed in a web
>> application environment"
>> 
>> now i've only seen examples referencing the datasource inside an action
> 
>> servlet, this appears to go against the design pattern. So how do i do
>> this? have i neglected to find the correct example? why are all the
>> examples of how to reference the datasource breaking the aforementioned
> 
>> priciple? please i'm very confused ..
>> 
>> many thanks in advance
>> 
>> mark
>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> 
>> For additional commands, e-mail:
>> 
>> 
>> 
>> 
>> -- End of Forwarded Message
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> 
>> For additional commands, e-mail:
>> 
>> 
>>  
>> 
> 
> 
> --
> To unsubscribe, e-mail:
> 
> For additional commands, e-mail:
> 
> 
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 
> 


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: dataSources outside of actionservlet

2002-12-17 Thread Edgar P. Dollin
Context env = (Context) new
InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) env.lookup("yourconnection");
conn = ds.getConnection();

Edgar
-Original Message-
From: Mark [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, December 17, 2002 10:13 AM
To: Struts Users Mailing List
Subject: Re: dataSources outside of actionservlet


I know that , i've read that .. But I what i really want to know is this

Without importing any servlet stuff

Some_means_of_getting_to_details_in_config_xml.getDatasource(mykey);

Many thanks mark

On 17-12-2002 15:17, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:

> Another option is to aquire the database connection via jndi when you 
> need it.
> 
> Edgar
> 
> -Original Message-
> From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 9:05 AM
> To: 'Struts Users Mailing List'
> Subject: Re: FW: dataSources outside of actionservlet
> 
> 
> The normal thing to is the following: You aquire a database connection

> in the action class and pass it on as a parameter to the bean's 
> database
> 
> methods.
> 
> --- Matthias
> 
> Mark wrote:
> 
>> Sorry to repost this question, but the more i think about it the more

>> i
> 
>> think it a reasonable one (please tell me if i'm wrong).
>> 
>> 
>> -- Forwarded Message
>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>> Reply-To: "Struts Users Mailing List" 
>> <[EMAIL PROTECTED]>
>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>> Subject: dataSources outside of actionservlet
>> 
>> hello
>> 
>> you'll all have to forgive my stupidity but i've been having real 
>> problems trying to reference the datasource specified in config.xml 
>> in my business logic classes.
>> 
>> I've been very good and seperated everything as one should. but i 
>> really need a straight answer to this (i.e. an example that works).
>> 
>> "For maximum code re-use, business logic beans should be designed and

>> implemented so that they do not know they are being executed in a web

>> application environment"
>> 
>> now i've only seen examples referencing the datasource inside an 
>> action
> 
>> servlet, this appears to go against the design pattern. So how do i 
>> do this? have i neglected to find the correct example? why are all 
>> the examples of how to reference the datasource breaking the 
>> aforementioned
> 
>> priciple? please i'm very confused ..
>> 
>> many thanks in advance
>> 
>> mark
>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail: 
>> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail: 
>> <mailto:[EMAIL PROTECTED]>
>> 
>> 
>> 
>> -- End of Forwarded Message
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail: 
>> <mailto:[EMAIL PROTECTED]>
>> 
>>  
>> 
> 
> 
> --
> To unsubscribe, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 
> 
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 
> 


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


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




Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
Thanks edgar.. 

For those folks who are starting out or don't read binary

Context and InitialContext are part of the javax.naming package

So you'll need to 
import javax.naming.Context;
import javax.naming.InitialContext;

The javadocs are less cryptic.. Sometimes is just knowing which ones one has
to read.. 

Many thanks again mark


On 17-12-2002 17:18, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:

>   Context env = (Context) new
> InitialContext().lookup("java:comp/env");
>   DataSource ds = (DataSource) env.lookup("yourconnection");
>   conn = ds.getConnection();
> 
> Edgar
> -Original Message-
> From: Mark [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 17, 2002 10:13 AM
> To: Struts Users Mailing List
> Subject: Re: dataSources outside of actionservlet
> 
> 
> I know that , i've read that .. But I what i really want to know is this
> 
> Without importing any servlet stuff
> 
> Some_means_of_getting_to_details_in_config_xml.getDatasource(mykey);
> 
> Many thanks mark
> 
> On 17-12-2002 15:17, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:
> 
>> Another option is to aquire the database connection via jndi when you
>> need it.
>> 
>> Edgar
>> 
>> -Original Message-
>> From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, December 17, 2002 9:05 AM
>> To: 'Struts Users Mailing List'
>> Subject: Re: FW: dataSources outside of actionservlet
>> 
>> 
>> The normal thing to is the following: You aquire a database connection
> 
>> in the action class and pass it on as a parameter to the bean's
>> database
>> 
>> methods.
>> 
>> --- Matthias
>> 
>> Mark wrote:
>> 
>>> Sorry to repost this question, but the more i think about it the more
> 
>>> i
>> 
>>> think it a reasonable one (please tell me if i'm wrong).
>>> 
>>> 
>>> -- Forwarded Message
>>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>>> Reply-To: "Struts Users Mailing List"
>>> <[EMAIL PROTECTED]>
>>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>>> Subject: dataSources outside of actionservlet
>>> 
>>> hello
>>> 
>>> you'll all have to forgive my stupidity but i've been having real
>>> problems trying to reference the datasource specified in config.xml
>>> in my business logic classes.
>>> 
>>> I've been very good and seperated everything as one should. but i
>>> really need a straight answer to this (i.e. an example that works).
>>> 
>>> "For maximum code re-use, business logic beans should be designed and
> 
>>> implemented so that they do not know they are being executed in a web
> 
>>> application environment"
>>> 
>>> now i've only seen examples referencing the datasource inside an
>>> action
>> 
>>> servlet, this appears to go against the design pattern. So how do i
>>> do this? have i neglected to find the correct example? why are all
>>> the examples of how to reference the datasource breaking the
>>> aforementioned
>> 
>>> priciple? please i'm very confused ..
>>> 
>>> many thanks in advance
>>> 
>>> mark
>>> 
>>> 
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> For additional commands, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> 
>>> 
>>> 
>>> -- End of Forwarded Message
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>>> For additional commands, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> 
>>>  
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> 
>> 
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 


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




Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
Okay.. We're almost there, but the env.lookup("yourconnection") bit is the
key that is specified in config.xml 'right?'



Doesn't work like this it throws an exception It tells be yourname is
not bound in this context...

While I'm sure , in fact i know there's a good reason for this, I usually
prefer to enrich my understanding after something is running

Prehaps i should try denistry rather than becoming a dustman..

Many thanks mark

On 17-12-2002 17:45, "Mark" <[EMAIL PROTECTED]> wrote:

> Thanks edgar.. 
> 
> For those folks who are starting out or don't read binary
> 
> Context and InitialContext are part of the javax.naming package
> 
> So you'll need to
> import javax.naming.Context;
> import javax.naming.InitialContext;
> 
> The javadocs are less cryptic.. Sometimes is just knowing which ones one has
> to read.. 
> 
> Many thanks again mark
> 
> 
> On 17-12-2002 17:18, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:
> 
>>   Context env = (Context) new
>> InitialContext().lookup("java:comp/env");
>>   DataSource ds = (DataSource) env.lookup("yourconnection");
>>   conn = ds.getConnection();
>> 
>> Edgar
>> -Original Message-
>> From: Mark [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, December 17, 2002 10:13 AM
>> To: Struts Users Mailing List
>> Subject: Re: dataSources outside of actionservlet
>> 
>> 
>> I know that , i've read that .. But I what i really want to know is this
>> 
>> Without importing any servlet stuff
>> 
>> Some_means_of_getting_to_details_in_config_xml.getDatasource(mykey);
>> 
>> Many thanks mark
>> 
>> On 17-12-2002 15:17, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:
>> 
>>> Another option is to aquire the database connection via jndi when you
>>> need it.
>>> 
>>> Edgar
>>> 
>>> -Original Message-
>>> From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
>>> Sent: Tuesday, December 17, 2002 9:05 AM
>>> To: 'Struts Users Mailing List'
>>> Subject: Re: FW: dataSources outside of actionservlet
>>> 
>>> 
>>> The normal thing to is the following: You aquire a database connection
>> 
>>> in the action class and pass it on as a parameter to the bean's
>>> database
>>> 
>>> methods.
>>> 
>>> --- Matthias
>>> 
>>> Mark wrote:
>>> 
>>>> Sorry to repost this question, but the more i think about it the more
>> 
>>>> i
>>> 
>>>> think it a reasonable one (please tell me if i'm wrong).
>>>> 
>>>> 
>>>> -- Forwarded Message
>>>> From: "Mark Lowe" <[EMAIL PROTECTED]>
>>>> Reply-To: "Struts Users Mailing List"
>>>> <[EMAIL PROTECTED]>
>>>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>>>> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>>>> Subject: dataSources outside of actionservlet
>>>> 
>>>> hello
>>>> 
>>>> you'll all have to forgive my stupidity but i've been having real
>>>> problems trying to reference the datasource specified in config.xml
>>>> in my business logic classes.
>>>> 
>>>> I've been very good and seperated everything as one should. but i
>>>> really need a straight answer to this (i.e. an example that works).
>>>> 
>>>> "For maximum code re-use, business logic beans should be designed and
>> 
>>>> implemented so that they do not know they are being executed in a web
>> 
>>>> application environment"
>>>> 
>>>> now i've only seen examples referencing the datasource inside an
>>>> action
>>> 
>>>> servlet, this appears to go against the design pattern. So how do i
>>>> do this? have i neglected to find the correct example? why are all
>>>> the examples of how to reference the datasource breaking the
>>>> aforementioned
>>> 
>>>> priciple? please i'm very confused ..
>>>> 
>>>> many thanks in advance
>>>> 
>>>> mark
>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <mailto:[EMAIL PROTECTED]>
>>>> For additional commands, e-mail:
>>>> <mailto:[EMAIL PROTECTED]>
>>>> 
>>>> 
>>>> 
>>>> -- End of Forwarded Message
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>>> For additional commands, e-mail:
>>>> <mailto:[EMAIL PROTECTED]>
>>>> 
>>>>  
>>>> 
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> For additional commands, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>>> For additional commands, e-mail:
>>> <mailto:[EMAIL PROTECTED]>
>>> 
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail:
>> <mailto:[EMAIL PROTECTED]>
>> 
>> 
>> --
>> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>> 
>> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 


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




Re: dataSources outside of actionservlet

2002-12-17 Thread J Aaron Farr
On Tue, 17 Dec 2002 17:45, "Mark" <[EMAIL PROTECTED]> wrote:
>
>Thanks edgar.. 
>
>For those folks who are starting out or don't read binary
>
>Context and InitialContext are part of the javax.naming package
>
>So you'll need to 
>import javax.naming.Context;
>import javax.naming.InitialContext;
>
>The javadocs are less cryptic.. Sometimes is just knowing which ones one has
>to read.. 
>
>Many thanks again mark
>
>
>On 17-12-2002 17:18, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:
>>
>>   Context env = (Context) new
>> InitialContext().lookup("java:comp/env");
>>   DataSource ds = (DataSource) env.lookup("yourconnection");
>>   conn = ds.getConnection();


Here's another way to do it without using JNDI:

Given a stuts-config.xml file with a datasource like this:

   
  
  
  ...
  
   

You can access a database connection in your Action like this:

   Connection dbCon = null;
   
   ServletContext context = servlet.getServletContext();
   DataSource ds = (DataSource) context.getAttribute("myDatabase");
   
   try{
 dbCon = ds.getConnection();
 ...

Now at this point you want to use a "model" or "business" object that handles
that actual logic.  For example, suppose we have a Product class:

 Product product = new Product();
 List productList = product.getProductList(dbCon);

Or something like that.

This should keep proper MVC design.  If anyone has a good reason why one should
use JNDI rather than the servlet context, I'd like to here it.  (I guess I can
think of a few cases...).

Also, I found the DAO (Data Access Object) pattern implemented in the JPetStore
example helpful in learning how to properly seperate models and actions. 
JPetStore is a Struts implementation of Sun's J2EE PetStore.  It uses its own
database connection pooling, but the DAO stuff is good nonetheless.  JPetStore
can be found at http://ibatis.com/jpetstore/jpetstore.html

Hope that helps.
jaaron

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: dataSources outside of actionservlet

2002-12-17 Thread Mark
Thanks the last answer does the job, thanks jaaron..

The JNDI solution seemed a bit crack induced and a bit too cyptic for my low
iq.. :)

Cheers again mark

On 17-12-2002 19:52, "J Aaron Farr" <[EMAIL PROTECTED]> wrote:

> On Tue, 17 Dec 2002 17:45, "Mark" <[EMAIL PROTECTED]> wrote:
>> 
>> Thanks edgar.. 
>> 
>> For those folks who are starting out or don't read binary
>> 
>> Context and InitialContext are part of the javax.naming package
>> 
>> So you'll need to
>> import javax.naming.Context;
>> import javax.naming.InitialContext;
>> 
>> The javadocs are less cryptic.. Sometimes is just knowing which ones one has
>> to read.. 
>> 
>> Many thanks again mark
>> 
>> 
>> On 17-12-2002 17:18, "Edgar P. Dollin" <[EMAIL PROTECTED]> wrote:
>>> 
>>>   Context env = (Context) new
>>> InitialContext().lookup("java:comp/env");
>>>   DataSource ds = (DataSource) env.lookup("yourconnection");
>>>   conn = ds.getConnection();
> 
> 
> Here's another way to do it without using JNDI:
> 
> Given a stuts-config.xml file with a datasource like this:
> 
>  
>   type="org.apache.struts.util.GenericDataSource">
> 
> ...
> 
>  
> 
> You can access a database connection in your Action like this:
> 
>  Connection dbCon = null;
>  
>  ServletContext context = servlet.getServletContext();
>  DataSource ds = (DataSource) context.getAttribute("myDatabase");
>  
>  try{
>dbCon = ds.getConnection();
>...
> 
> Now at this point you want to use a "model" or "business" object that handles
> that actual logic.  For example, suppose we have a Product class:
> 
>Product product = new Product();
>List productList = product.getProductList(dbCon);
> 
> Or something like that.
> 
> This should keep proper MVC design.  If anyone has a good reason why one
> should
> use JNDI rather than the servlet context, I'd like to here it.  (I guess I can
> think of a few cases...).
> 
> Also, I found the DAO (Data Access Object) pattern implemented in the
> JPetStore
> example helpful in learning how to properly seperate models and actions.
> JPetStore is a Struts implementation of Sun's J2EE PetStore.  It uses its own
> database connection pooling, but the DAO stuff is good nonetheless.  JPetStore
> can be found at http://ibatis.com/jpetstore/jpetstore.html
> 
> Hope that helps.
> jaaron
> 
> __
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 
> 


--
To unsubscribe, e-mail:   
For additional commands, e-mail: