Is this code using connection pooling? :-)

S

Simon Harvey

Hi there,

I have copied the following code which seems to work in my webapp:

Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource dataSource = (DataSource) ctx.lookup("jdbc/datasource");


The reason why I have done this is because I want to use connection pooling
and I have made the necessary changes to tomcat to support this. But my
question is simply, assuming that I have done everything correctly, with the
code above, am I know ready to start getting pooled connections when i ask
the datasource?

The reason why I ask is because I have seen code that makes specific
reference to ConnectionPools and so on, but as you can see, the code above
says nothing about pools at all. I did copy the code from an article on CP
so I'm sure it is, but I just need to confirm and ask why some examples are
dong in a different way?

Doing it this way, does a datasource automatically provide connection
pooling? Do they all do that? If some don't, what happens - does the code
need changed?


Thanks everyone

Take care

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top