On Thu, 25 Jul 2002, Pop Marius wrote:
> Date: Thu, 25 Jul 2002 11:00:05 +0200
> From: Pop Marius <[EMAIL PROTECTED]>
> Reply-To: Tomcat Developers List <[EMAIL PROTECTED]>
> To: tomcat <[EMAIL PROTECTED]>
> Subject: connection pooling
>
>
> Hi everybody !
>
> I'm using Tomcat 4 and my application works. To get a connection to database I have
>the following code:
>
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env");
>
> DataSource ds = (DataSource)envCtx.lookup("jdbc/orgDB");
> return ds.getConnection();
>
> and of course in the server.xml the necessary resource requirements !
> The application works fine, but How could I ensure myself that the
> connections provided are reused, that the pooling machine works, and I
> really have a pooling mechanism.
>
> How can I test it ! The documentation sais that ds.getConnection() gets
> a connection from the pool (which pool, how) but I'm not sure that !
>
It gets a connection from the pool that you configured with your resource
settings in server.xml.
> Any idea would be helpful !
>
The normal pattern for using a connection from a data source like this
(including your code from above):
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/orgDB");
Connection conn= ds.getConnextion();
... use the connection to do your database access ...
conn.close();
The last call doesn't actually close the underlying database connection --
it just returns this instance to the connection pool.
>
>
>
> Pop Marius Lucian
>
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>