Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

JasperReportsIntegration with PostgreSQL #13

I tested JasperReportsIntegration with Oracle, it was ok. But with PostgreSQL was no luck.
There's postgresql-42.2.14.jar in \lib directory.
#============================================================ [datasource:postgresql]

I start http://localhost:8090/JasperReportsIntegration/
and click on the line 'postgresql jdbc Test'
and receive the message:

java.lang.RuntimeException: Could not connect via JDBC: ????? ???????? URL Oracle
(Invalid Oracle URL specified)

Why Oracle URL? I use Postgresql.
Because Class.forName("oracle.jdbc.driver.OracleDriver")?
But With JDBC 4.0, applications no longer need to issue a Class.forName() on the driver name; instead, the DriverManager will find an appropriate JDBC driver when the application requests a Connection.

Can you help me, please?

  • replies 6
  • views 2.6K
  • likes 0

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

# Native JNDI datasource, to be configured in the application server
# 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:

<?xml version="1.0" encoding="UTF-8"?>

<Context path="/JasperReportsIntegration" debug="5" reloadable="true"

    <!-- parameter definition: -->
    <!-- minimum connections in pool: 3 -->
    <!-- check valid session: each 5 minutes  -->
    <Resource name="jdbc/jndi_test" auth="Container" type="javax.sql.DataSource"
              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"


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()
		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) {"JNDI lookup failed for " + jndiName
							+ ", trying JDBC now...");
		} else if (dataSourceDef.type.equals("jdbc")){
			// ----------------------------------------------------
			// use JDBC connection next
			// ----------------------------------------------------
			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

					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();
						// set connection parameters
						dataSources.put(dsName, ocpds);

					pc = ocpds.getPooledConnection();
					conn = pc.getConnection();"successfully connected to " + dataSourceDef.url
							+ " with user: " + dataSourceDef.username);
				} catch (SQLException e) {
					Utils.throwRuntimeException("Could not connect via JDBC: "
							+ e.getMessage());
		if (conn != null)"dataSource loaded:" + dsName);

		return conn;

And I use for jndi the following prefix:

private String _jndiPrefix = "java:comp/env/jdbc/";

Hope that helps.

ViktorAfnt · Author

Hi Dietmar,
I success with Tomcat.
Thanks for your help!

Best regards, Viktor.

1. Install Apache Tomcat ([Tomcat directory] for example = "E:\apache-tomcat-9.0.36")
2. Change the port for your local Tomcat installation ( for example = 8181
	Once the basic Apache Tomcat installation works, stop the Apache Tomcat server.

3. Install the oracle JDBC drivers. Copy the files ojdbc8.jar, orai18n.jar and postgresql-42.2.14.jar into [Tomcat directory]\lib
4. Copy the file webapp\JasperReportsIntegration.war (version into the directory [Tomcat directory]\webapps.
5. Start the Apache Tomcat server
    During startup, Tomcat will detect the new application and deploy the file automatically into the directoy [Tomcat directory]\webapps\JasperReportsIntegration.
6. Now you can test JasperReportsIntegration
	Start Tomcat (from command line at "[Tomcat directory]\bin"  enter "startup")
	Enter "http://localhost:8181/JasperReportsIntegration/" in brower address line
	Check "Basic connectivity tests" and "Basic report tests"
7. Stop Tomcat (from command line at "[Tomcat directory]\bin"  enter "shutdown")
8. For new datasource adding:
	add it in (with type = jdbc or jndi; "[Tomcat directory]\webapps\JasperReportsIntegration\WEB-INF\conf") 
		Example for JNDI case:
	add the resource in context.xml ("[Tomcat directory]\webapps\JasperReportsIntegration\META-INF")
		Example for JNDI case:
			<Resource name="jdbc/postgre" auth="Container" type="javax.sql.DataSource"
					  validationQuery="select user"

Hi Victor,

this sounds great. Could you please share the exact configuration steps to make it work?
I am not using PostgreSQL ... but perhaps it could be valuable for other people.

Thank you


I am so sorry, overlooked it. My first impression was that you quoted my description.
My bad.

Thanks a lot and glad it works :) .


Hi @ViktorAfnt,

could you please close the issue? I believe you can mark it as "answer".

Thank you

daust added the waiting for reply from reporter label