You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Koon Yue Lam <ki...@gmail.com> on 2004/07/16 04:18:03 UTC
About datasource
Hi !
I have successfully use struts to connect MySql but I wonder do I
using the database connection pool, or just a new connection for each
request??
All I did is very simple stuffs and I follow strict to the database
How-To section of struts doc.
How can I know I am actually using a connection pool ??
Regards
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: About datasource
Posted by Marco Mistroni <mm...@waersystems.com>.
Hello,
How about retrieving it from JNDI?
How about a plugIn (DAOFactory) that retrieves the DataSource via
JNDI and then initializes each DAO with the DataSource?
Regars
marco
-----Original Message-----
From: Koon Yue Lam [mailto:kisstech@gmail.com]
Sent: 16 July 2004 10:18
To: Struts Users Mailing List
Subject: Re: About datasource
Hi, after some thinking, I have another problem, ^^
If I am using an Action (which extent the Struts' Action class), I can
get the Datasource by calling getDataSource()
But now I want to write my own data assess object which shouldn't
extent Action, I don't know what way I can get the datasource from the
pool.....
any help??
Regards
---------------------------------------------------------------------
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: About datasource
Posted by Koon Yue Lam <ki...@gmail.com>.
Hi, after some thinking, I have another problem, ^^
If I am using an Action (which extent the Struts' Action class), I can
get the Datasource by calling getDataSource()
But now I want to write my own data assess object which shouldn't
extent Action, I don't know what way I can get the datasource from the
pool.....
any help??
Regards
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: About datasource
Posted by Koon Yue Lam <ki...@gmail.com>.
Thanks so much !!
u really helps and quick response !!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: About datasource
Posted by Craig McClanahan <cr...@apache.org>.
Koon Yue Lam wrote:
>Hi !
>I have successfully use struts to connect MySql but I wonder do I
>using the database connection pool, or just a new connection for each
>request??
>All I did is very simple stuffs and I follow strict to the database
>How-To section of struts doc.
>How can I know I am actually using a connection pool ??
>
>
>
If you are using an object whose class implements javax.sql.DataSource,
you are indeed using a connection pool. The number of connections in
the pool is determined by your configuration properties, and the
getConnection() method will reuse an existing connection from the pool
(if there is one), only creating new connections when necessary -- and
when the total number of connections you specify has not yet been reached.
A very important consideration when using connection pools is to ensure
that you *always* return the connection to the pool, even when an
exception is encountered. One pattern I like to follow that ensures
this is to use a "try ... finally" block, something like this:
Connection conn = null;
DataSource ds = ...; // Get a reference to your data source
try {
conn = ds.getConnection(); // Allocate a connection from the pool
... use the connection as necessary ...
} catch (SQLException e) {
... deal with exceptions as needed ...
} finally {
// If you got a connection from the pool, the close() method
// does *not* close the physical connection; it returns this one
// to the available pool
if (conn != null) {
conn.close();
}
}
The "finally" block is always executed (even if an exception occurs), so
this design idiom ensures that there's no way for me to forget to return
a connection when I am done with it.
>Regards
>
>
>
Craig McClanahan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org