Dear All,
I am doing connection pooling with tomcat 6. And i am doing this very first
time before today i had no idea about connection pooling. I want to ensure
that it is the correct way or not.
Please do me correct if i am doing wrong anywhere. I am explaining you all
steps done by me-
*1. Have created a context.xml*
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/MaxDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:MySQL://localhost:3306/MaxDB?zeroDateTimeBehavior=convertToNull"/>
</Context>
*2. Mapping in web.xml*
<resource-ref>
<description>MySql DataSource</description>
<res-ref-name>jdbc/MaxDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
*3. Then on my servlet i am getting the object of connection like this-*
private static InitialContext ic;
protected static DataSource datasource;
private static Context ctx;
protected static Connection getConnection() throws DatabaseException
{
Connection conn = null;
try
{
ctx = new InitialContext();
datasource = (DataSource)
ctx.lookup("java:/comp/env/jdbc/MaxDB");
conn = datasource.getConnection();
}
catch (Exception ex)
{
}
return conn;
}
Is that it or we need to do anything else for connection pooling. As i
google then i found there is an API Commons DBCP so tomcat use it
internally or we have to do something with this.
Using this i am able to get the connection object.But at the second request
how i will validate that its taking the connection object from pool and not
creating the new con object. Even i am not sire that here i am using
connection pooling or getting object of connection simply using datasource.
Please assist me!
Thanking You!
*Best Regards, *
*Saurabh Sarasvat*