In older versions of Jasper reports default data source type was JDBC.

But Jasper 5 and higher recommends JNDI and if you use for reports some database functions which write into tables during their run you will find that they are failing with old JDBC connections.

JNDI connections are defined in META-INF/context.xml file like this:


<Resource name="jdbc/your_pg_database" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="your_pg_user" password="your_pg_password"
driverClassName="org.postgresql.Driver"
validationQuery="select 1"
testOnBorrow="true"
url="jdbc:postgresql://localhost:5432/jasperserver"   />

In the same way you create sections for all databases you need to connect.

But – switch to another connection type is not exactly easy. Tibco Jaspersoft Studio will not help you.

You cannot simply change type of connection (still true in 6.1). Also if you try to create new one then you will see that you would need to manually change data source in all reports which use it.

So far the easiest way I found is to manually export definitions using “js-export.sh”, edit export xml file and again update reports on server using “js-import.sh –update”.

XML format of old JDBC connection looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<jdbcDataSource>
<folder>/public/PS_Performance_Reports/Data_Sources</folder>
<name>NRS</name>
<version>0</version>
<label>NRS</label>
<description>Maintenance</description>
<creationDate></creationDate>
<updateDate></updateDate>
<driver>org.postgresql.Driver</driver>
<connectionUrl>jdbc:postgresql://127.0.0.1:5432/nrs</connectionUrl>
<connectionUser>your_pg_user</connectionUser>
<connectionPassword>your_pg_password</connectionPassword>
</jdbcDataSource>

 

XML of new JNDI connection:

<?xml version="1.0" encoding="UTF-8"?>
<jndiJdbcDataSource exportedWithPermissions="false">
<folder>/public/PS_Performance_Reports/Data_Sources</folder>
<name>NRS</name>
<version>0</version>
<label>NRS</label>
<description>Maintenance</description>
<creationDate></creationDate>
<updateDate></updateDate>
<jndiName>jdbc/your_pg_database</jndiName>
</jndiJdbcDataSource>

So you simply change main tag “jdbcDataSource” to “jndiJdbcDataSource” and replace last 4 lines with new “jndiName” tag. Name in “jndiName” is the same as in context.xml “Resource name=” attribute.

After import into database your connections are changed to JNDI.