Hi Viktor,
this tool was specifically designed for Oracle and never intented for any other databases. But I do support two different approaches.
When you are using the type=jdbc, it will create an Oracle specific Connection Pool. This is how it is implemented. Not a single connection, but a managed connection pool.
When you are using the type=jndi you can configure it in Tomcat itself. You could use this approach.
E.g. in the application.properties:
#====================================================================
# Native JNDI datasource, to be configured in the application server
# name: jndi_test
#====================================================================
[datasource:jndi_test]
type=jndi
name=jndi_test
Then you also need to create a file called JasperReportsIntegration.xml and place it into the directory: $TomcatHome\conf\Catalina\localhost\JasperReportsIntegration.xml. It is explained in older versions how to do that. Most people have moved to the oracle specific jdbc connection approach: http://www.opal-consulting.de/downloads/free_tools/JasperReportsIntegration/2.0.0/doc/Installation-J2EE-Tomcat.html
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/JasperReportsIntegration" debug="5" reloadable="true"
crossContext="true">
<!-- parameter definition: http://commons.apache.org/dbcp/configuration.html -->
<!-- minimum connections in pool: 3 -->
<!-- check valid session: each 5 minutes -->
<Resource name="jdbc/jndi_test" auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
maxActive="20" maxIdle="10" maxWait="-1"
initialSize="4" minIdle="3" validationQuery="select user from dual"
testWhileIdle="true" testOnBorrow="true" timeBetweenEvictionRunsMillis="300000"
numTestsPerEvictionRun="100" minEvictableIdleTimeMillis="10000"
url="jdbc:oracle:thin:@127.0.0.1:1521:XE"
username="my_oracle_user"
password="my_oracle_user_pwd"
/>
</Context>
I use the following code to connect to the database:
/**
* Get a connection for a data source from the connection pool. First we try
* to get a connection from the JNDI datasources. If there is no
* configuration available for this datasource, then create a regular JDBC
* connection. The connection pool is created upon the first request.
*
* @param dsName the name of the data source, e.g. "default"
* @return Connection
*/
public Connection getConnection(String dsName) {
logger.trace("lookup dataSource:" + dsName);
DataSourceDefinition dataSourceDef = AppConfig.getInstance()
.getDataSourceDefinition(dsName);
Connection conn = null;
if (dataSourceDef == null)
Utils.throwRuntimeException("Datasource " + dsName + " could not be found.");
if (dataSourceDef.type.equals("jndi")){
// ----------------------------------------------------
// use the JNDILookup first
// ----------------------------------------------------
if (initialContext != null) {
String jndiName = this.jndiPrefix + dsName;
logger.debug("use JNDI to lookup dataSource:" + jndiName);
try {
DataSource ds = (DataSource) initialContext.lookup(jndiName);
if (ds != null) {
conn = ds.getConnection();
}
} catch (Exception e) {
logger.info("JNDI lookup failed for " + jndiName
+ ", trying JDBC now...");
}
}
} else if (dataSourceDef.type.equals("jdbc")){
// ----------------------------------------------------
// use JDBC connection next
// http://docs.oracle.com/cd/B19306_01/java.102/b14355/concache.htm
// ----------------------------------------------------
if (conn == null) {
logger.debug("use JDBC to lookup dataSource:" + dsName);
OracleConnectionPoolDataSource ocpds;
PooledConnection pc;
try {
logger.trace("retrieve connectionPoolDataSource from HashMap first");
ocpds = dataSources
.get(dsName);
if (ocpds == null) {
logger.trace("dataSource not found in HashMap, initialize a new connection pool and store in HashMap");
// set cache properties
java.util.Properties prop = new java.util.Properties();
prop.setProperty("InitialLimit", "3");
prop.setProperty("MinLimit", "3");
prop.setProperty("MaxLimit", "50");
ocpds = new OracleConnectionPoolDataSource();
ocpds.setURL(dataSourceDef.url);
ocpds.setUser(dataSourceDef.username);
ocpds.setPassword(dataSourceDef.password);
// set connection parameters
ocpds.setConnectionProperties(prop);
dataSources.put(dsName, ocpds);
}
pc = ocpds.getPooledConnection();
conn = pc.getConnection();
logger.info("successfully connected to " + dataSourceDef.url
+ " with user: " + dataSourceDef.username);
} catch (SQLException e) {
Utils.throwRuntimeException("Could not connect via JDBC: "
+ e.getMessage());
}
}
}
if (conn != null)
logger.info("dataSource loaded:" + dsName);
return conn;
}
}
And I use for jndi the following prefix:
private String _jndiPrefix = "java:comp/env/jdbc/";
Hope that helps.
~Dietmar.