You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Thibaut L." <tl...@cvdunet.com> on 2005/05/27 13:49:53 UTC
DataBase connection
hi, i'd like to access mysql from the my own controller init method.
I usually do :
|dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
but i have no request object in my init method.
Any idea ?
thanks.
|
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: DataBase connection
Posted by Martin Gainty <mg...@hotmail.com>.
For example if you were to use postgres default DataSource you would need to
identify the inidividual properties as well as the actual driver class which
comes with the Struts Distro so struts-config.xml would identify the Generic
Data Source via
<!-- configuration for GenericDataSource wrapper -->
<data-source>
<set-property
property="autoCommit"
value="false"/>
<set-property
property="description"
value="Example Data Source Configuration"/>
<set-property
property="driverClass"
value="org.postgresql.Driver"/>
<set-property
property="maxCount"
value="4"/>
<set-property
property="minCount"
value="2"/>
<set-property
property="password"
value="mypassword"/>
<set-property
property="url"
value="jdbc:postgresql://localhost/mydatabase"/>
<set-property
property="user"
value="myusername"/>
</data-source>
courtesy of Linux Struts How to located at
http://linux.com.hk/docs/struts/faqs/database.html
Martin-
001-617-852-7822
----- Original Message -----
From: "Thibaut L." <tl...@cvdunet.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, May 27, 2005 8:25 AM
Subject: Re: DataBase connection
> thank you for answering so fast.
> i knew there were this object but i don't find how to use it.
> i've tried : DataSource aDataSource = (DataSource)
> dataSources.entrySet().iterator().next();
> but it doesn't work.
>
> Martin Gainty a écrit :
>
>> should be identified as DataSources within your ActionServlet take a look
>> at
>> http://struts.apache.org/api/org/apache/struts/action/ActionServlet.html#dataSources
>> HTH,
>> Martin-
>>
>> ----- Original Message ----- From: "Thibaut L." <tl...@cvdunet.com>
>> To: <us...@struts.apache.org>
>> Sent: Friday, May 27, 2005 7:49 AM
>> Subject: DataBase connection
>>
>>
>>> hi, i'd like to access mysql from the my own controller init method.
>>> I usually do :
>>>
>>> |dataSource = getDataSource(request);
>>> myConnection = dataSource.getConnection();
>>>
>>> but i have no request object in my init method.
>>> Any idea ?
>>>
>>> thanks.
>>> |
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: DataBase connection
Posted by "Thibaut L." <tl...@cvdunet.com>.
thank you for answering so fast.
i knew there were this object but i don't find how to use it.
i've tried : DataSource aDataSource = (DataSource)
dataSources.entrySet().iterator().next();
but it doesn't work.
Martin Gainty a écrit :
> should be identified as DataSources within your ActionServlet take a
> look at
> http://struts.apache.org/api/org/apache/struts/action/ActionServlet.html#dataSources
>
> HTH,
> Martin-
>
> ----- Original Message ----- From: "Thibaut L." <tl...@cvdunet.com>
> To: <us...@struts.apache.org>
> Sent: Friday, May 27, 2005 7:49 AM
> Subject: DataBase connection
>
>
>> hi, i'd like to access mysql from the my own controller init method.
>> I usually do :
>>
>> |dataSource = getDataSource(request);
>> myConnection = dataSource.getConnection();
>>
>> but i have no request object in my init method.
>> Any idea ?
>>
>> thanks.
>> |
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: DataBase connection
Posted by Martin Gainty <mg...@hotmail.com>.
should be identified as DataSources within your ActionServlet take a look at
http://struts.apache.org/api/org/apache/struts/action/ActionServlet.html#dataSources
HTH,
Martin-
----- Original Message -----
From: "Thibaut L." <tl...@cvdunet.com>
To: <us...@struts.apache.org>
Sent: Friday, May 27, 2005 7:49 AM
Subject: DataBase connection
> hi, i'd like to access mysql from the my own controller init method.
> I usually do :
>
> |dataSource = getDataSource(request);
> myConnection = dataSource.getConnection();
>
> but i have no request object in my init method.
> Any idea ?
>
> thanks.
> |
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org