Skip to content

Instantly share code, notes, and snippets.

@sbose78
Created May 22, 2013 05:46
Show Gist options
  • Save sbose78/5625490 to your computer and use it in GitHub Desktop.
Save sbose78/5625490 to your computer and use it in GitHub Desktop.
The config files used for Db Connection pooling
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/udhc-eclipse-tomcat6" docBase="udhc-eclipse-tomcat6" reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="20" maxIdle="5"
username="root" password="qwerty"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/udhc_local_db" />
<Resource name="jdbc/awsDB" auth="Container" type="javax.sql.DataSource"
testWhileIdle="true"
maxActive="30"
maxIdle="5"
maxWait="3000"
removeAbandoned="true"
logAbandoned="false"
removeAbandonedTimeout="3"
timeBetweenEvictionRunsMillis="300000"
username="sbose78" password="XXXXXX"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://udhc-amazoXXXXXXnortheast-1.rds.amazonaws.com:3306/health?autoReconnect=true" />
</Context>
public static Connection getPooledDbConnection() throws NamingException, SQLException
{
Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/TestDB");
Connection conn = ds.getConnection();
return conn;
}
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/awsDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment