Friday, February 19, 2010

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();
}


No comments:

Trying out the Dart Analysis Server

I wanted to see how the Dart Analysis Server was put together and worked. I started looking to see how I could wire it up and try out the co...