Without getting to far into connection pooling, it is often must simpler to use this mechanism to call a sql query from mirth:

Import this code template (from mirth menu, click “Channels”, click “Code templates”. Create new library if there is not one. Then create a new code template and paste:

function executeSharedDBStatement(statement, isQuery, paramList)
{
var result;

try
{
var dbConn = globalMap.get("dbConn");

if (dbConn == null || dbConn.getConnection().isClosed())
{

dbConn = DatabaseConnectionFactory.createDatabaseConnection(configurationMap.get('DBDriver'),configurationMap.get('DBServerDatabase'),configurationMap.get('DBUserName'),configurationMap.get('DBPassword'));
globalMap.put("dbConn", dbConn);
}

if (paramList == undefined)
{
paramList = new Packages.java.util.ArrayList();
}

if (isQuery)
{
result = dbConn.executeCachedQuery(statement, paramList);
}
else
{
result = dbConn.executeUpdate(statement, paramList);
}
}
catch (e)
{
logger.error(e);
}
finally
{
return result;
}
}

In the global configuration map you will need to create variables:

DBDriver “org.postgresql.Driver” in my case”
DBServerDatabase “jdbc:postgresql://10.102.17.56/webchecks” in my case
DBUserName “the username”
DBPassword “the password”

You can then call a query that expects a result by (in this case a javascript db reader.

var sqlQuery = "select * from ..."
var result = executeSharedDBStatement(sqlQuery, true)
return result;