If you want to use connection pool in your project , Ensure that you have the following code set up for the Tomcat connection pooling to work in context.xml file:
1)Create file with name "context.xml" if it's not exist under directory "WebContent/META-INF/context.xml" with the following content:
For My Project , Please modify it with appropriate value :
<?xml version="1.0" encoding="UTF-8"?> <Context path="/dbcp" docBase="dbcp"> <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" removeAbandoned="true" removeAbandonedTimeout="30" maxActive="80" maxIdle="30" maxWait="10000" username="sontn" password="nhantien" driverClassName="org.postgresql.Driver" url = "jdbc:postgresql://localhost/group8" useUnicode="true" characterEncoding="utf-8" characterSetResults="utf8" /> </Context>
Or you can copy file : context.xml into directory "$Catalian\webapps\axis2\META-INF"
How can you get connection pool?
In your webservice method : create method getConnection() with following content:
public Connection getConnection() { Connection connection = null; try { Context envCtx = (Context) new InitialContext()
.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB"); connection = ds.getConnection(); } catch (Exception e) { System.out.println("Connection error: " + e.getMessage()); } return connection; }
Thanks