Make DBCP Connection Pool Using Tomcat Resource Context

Setup JDBC DBCP (data base connection pooling) for use with any Java class.

Reference:
http://code.google.com/p/parsecsv2sql/source/browse/trunk/Csv2Sql/src/org/gonevertical/dts/lib/pooling/SetupInitialContext.java

How I set it up:
public DatabaseConnection(boolean pool) {
File executionlocation = null;
try {
executionlocation = new File(DatabaseConnection.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
String execPath = executionlocation.getParent();
execPath = StringUtil.getValue("(.*?)/war", execPath);
String path = execPath + "/war/META-INF/context.xml";
String contextXmlPath = path;
String tmpPath = "/home/branflake2267/tmp";
// make my own context
SetupInitialContext ic = new SetupInitialContext(tmpPath);
ic.setContextXmlFileLocation(contextXmlPath);
ic.run();
context = ic.getInitialContext();
}


Post a Comment

Popular posts from this blog

How to Get Date/Time in/with GWT

Encoding URL delimiters (for GWT)