getConnection in struts  
Author Message
Grzegorz Stasica





PostPosted: 2004-2-9 23:00:00 Top

java-programmer, getConnection in struts Hi,

I hope the question is addressed to the appropriate forum :)
First of all I'd like to say I'm new to struts. My question is how
should I getConnection to DB. I know how to read parameters for
connection but I'd like to make conections more robust. I mean I should
use ConnectionPool. I've some idea how to achieve it but..if I split my
application into tiers (presentation, conntroller, bo and dao) how can I
get Connection from DAO tier since I don't have access to server
context. I'm looking for some advice how to cope with such problems. Of
course I could pass in constructor these parameters but I don't think it
was good solution.
How did you solve problem with accessing db from your struts applications?

Rgs
 
Sudsy





PostPosted: 2004-2-10 1:17:00 Top

java-programmer >> getConnection in struts Grzegorz Stasica wrote:
> Hi,
>
> I hope the question is addressed to the appropriate forum :)
> First of all I'd like to say I'm new to struts. My question is how
> should I getConnection to DB. I know how to read parameters for
> connection but I'd like to make conections more robust. I mean I should
> use ConnectionPool. I've some idea how to achieve it but..if I split my
> application into tiers (presentation, conntroller, bo and dao) how can I
> get Connection from DAO tier since I don't have access to server
> context. I'm looking for some advice how to cope with such problems. Of
> course I could pass in constructor these parameters but I don't think it
> was good solution.
> How did you solve problem with accessing db from your struts applications?
>
> Rgs


I have this in my struts-config.xml:

<data-sources>
<data-source type="oracle.jdbc.pool.OracleDataSource">
<set-property property="description"
value="Oracle Data Source"/>
<set-property property="driverClass"
value="oracle.jdbc.driver.OracleDriver"/>
<set-property property="url"
value="jdbc:oracle:thin:@192.168.0.1:1521:XXXX"/>
<set-property property="maxCount" value="2"/>
<set-property property="minCount" value="1"/>
<set-property property="user" value="joe"/>
<set-property property="password" value="blow"/>
</data-source>
</data-sources>

This gives me a connection pool data source. My Action is coded
like this:

public ActionForward execute( ActionMapping mapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse resp ) {
....
DataSouce ds = getDataSource( req );
Connection conn = null;
try {
conn = ds.getConnection();
...

Pretty simple, eh?