Jump to content
  • This documentation is an older version of JasperReports Server Administration Guide. View the latest documentation.

    Working With Data Sources

    When adding a data source to JasperReports Server, several things can cause errors. Start by looking at the following general connectivity issues:

    Check that your database server is available and accepting TCP/IP connections from the host where JasperReports Server is installed.
    Check in your RDBMS that the username and password you're using are correct and have access to the selected database.
    Check for firewalls or network connectivity errors.

    Many databases, including MySQL, also require the user grants to include the specific host from which connections are allowed. Otherwise, when testing the JDBC connection, a connection may not be allowed even though the username and password are correct. For more information, refer to the MySQL documentation for setting up users.

    An easy way to test connectivity from the server to the database with a particular user is to use a tool such as SQuirreL or another DB query tool to connect to the database from the host of your JasperReports Server instance.

    Logging JDBC Operations

    You can enable additional logging to help you find the cause of the error. Set any or all of the following loggers in the server settings interface or in the .../WEB-INF/log4j.properties file:

    log4j.logger.com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.JdbcDataSourceService
    log4j.logger.com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.
    JndiJdbcDataSourceService
    log4j.logger.com.jaspersoft.jasperserver.war.action.ReportDataSourceAction
    log4j.logger.com.jaspersoft.commons.datarator.JdbcDataSet
    log4j.logger.com.jaspersoft.jasperserver.war.common.JasperServerUtil
    log4j.logger.com.jaspersoft.commons.semantic.dsimpl.JdbcDataSetFactory
    log4j.logger.com.jaspersoft.commons.semantic.metaapi.impl.jdbc.BaseJdbcMetaDataFactoryImpl
    log4j.logger.com.jaspersoft.jasperserver.war.validation.ReportDataSourceValidator

    JDBC Drivers

    As of JasperReports Server 5.1, JDBC driver management is automated and simplified. JasperReports Server ships with drivers for some databases, as listed in the dialog for creating data sources. If the JDBC driver for your database is not included, the system administrator can easily upload the driver and use it immediately in a data source.

    For instructions on updating JDBC drivers without restarting the server, see Managing JDBC Drivers. For instructions on adding JDBC drivers when using JBoss, see the next section.

    JDBC Drivers on JBoss

    For modularity reasons, the JBoss application server does not allow web applications such as JasperReports Server to change executable files, such as JDBC drivers, on the fly. In order for JDBC drivers to appear in the list of available drivers and be selectable, you must configure JBoss before you use the drivers to create a JDBC data source.

    To add JDBC drivers on JBoss:

    1. Download or copy the JDBC driver JAR file to the .../WEB-INF/lib/ directory.
    2. Edit the jboss-deployment-structure.xml file as described in the following table:

    Configuring JBoss for JDBC drivers

    Configuration File

    .../META-INF/jboss-deployment-structure.xml

    Property

    Description

    resource-root path="<driver>.jar"

    Locate the resource root element for the JDBC driver you added and uncomment it. The name of the JAR file must match exactly the name of the JDBC driver that you upload. You can add a new resource root element if the JDBC driver of your choice is not given in the commented list.

    3. Restart JBoss.

    Database Permissions

    When creating database users, you must ensure that they have the appropriate privileges to access data, as well as permission to connect from the server that JasperReports Server is running on.

    The database user that you specify in your data source definition needs the privileges to run SELECT queries on the tables used in your reports. The server blocks any DROP, INSERT, UPDATE, and DELETE SQL commands through its SQL injection protection. In some cases, additional permissions may be required to execute stored procedures, depending on your configuration and needs.
    If you accept the defaults during installation of JasperReports Server on Linux from an RPM using apt-get, rpm, or yum, the bundled PostgreSQL allows only the user who owns PostgreSQL to connect. Enter the following commands to connect:
    Many databases, including MySQL, also require that the user permissions name the specific host from which connections are allowed. Otherwise, when testing the JDBC connection, a connection may not be allowed even though the user name and password are correct. For example, see the MySQL documentation for setting up users.

    A fairly easy way to test permissions and connectivity is to use a tool such as SquirrelSQL or another DB query tool to connect to the database from the same host as JasperReports Server and to run typical queries against your database.

    JDBC Database URLs

    When you choose a JDBC driver, the data source creation wizard prompts you for the elements of the URL that are required for your database. In some cases, you may need to add certain arguments to the JDBC URL. Ensure that the database URL you entered when defining your JDBC data source is consistent with what is required for your specific database and database driver. The following table gives the default URLs and port numbers and examples of optional arguments supported by the most common databases:

    Database

    Default JDBC Database URL

    PostgreSQL

    jdbc:postgresql://<host>:5432/<db-name>

    MySQL and MariaDB

    jdbc:mysql://<host>:3306/<db-name>?tinyInt1isBit=false

    Oracle

    jdbc:tibcosoftware:oracle://<host>:1521;SID=ORCL

    SQL Server

    jdbc:tibcosoftware:sqlserver://<host>:1433;databaseName=<db-name>

    IBM DB2

    jdbc:tibcosoftware:db2://<host>:50000;databaseName=<db-name>

    Cassandra jdbc:cassandra://<host>:9042;DefaultKeyspace=
    Hive jdbc:tibcosoftware:hive://<host>:10001;TransactionMode=ignore
    Impala jdbc:impala://<host>:21050/default
    Redshift jdbc:tibcosoftware:redshift://<host>:5439;databaseName=<db-name>;TransactionMode=ignore
    SparkSQL jdbc:tibcosoftware:sparksql://<host>:10000;TransactionMode=ignore
    Salesforce jdbc:tibcosoftware:sforce://;SecurityToken=;TransactionMode=ignore;StmtCallLimit=1000;databaseName=[TMPDIR/]Salesforce

    SQL Functions with TIBCO JDBC Drivers

    As of JasperReports Server 5.6.1, TIBCO provides a set of JDBC drivers in the installed server. The TIBCO JDBC drivers are based on the Progress DataDirect Connect drivers and support a slightly different SQL syntax than the vendors' drivers. If you see errors like the one below when running reports or creating domains that use scalar functions, you'll need to modify your queries.

    For example, the following query does not work with the TIBCO JDBC drivers:

    The correct syntax for the TIBCO JDBC drivers is as follows:

    For more information, see the Progress DataDirect page on scalar functions.

    Enabling the TIBCO JDBC Drivers for Impala and Cassandra Data Sources

    Starting in JasperReports Server 6.4, only one JDBC driver is enabled for each data source type by default. JasperReports Serveruses the Simba JDBC drivers for Impala and Cassandra data sources by default. If you want to use the TIBCO JDBC drivers for Impala (tibcosoftware.jdbc.impala.ImpalaDriver) or Cassandra (tibcosoftware.jdbc.cassandra.CassandraDriver) data sources, you can modify the .../WEB-INF/applicationContext-webapp.xml file to make the drivers active.

    To enable the TIBCO JDBC drivers for Impala and Cassandra data sources:

    1. Open the file .../WEB-INF/applicationContext-webapp.xml for editing.
    2. Locate the jdbcTibcoConnectionMap bean and find the following lines for the inactive Impala and Cassandra JDBC drivers:
    3. Modify the lines as follows to enable the JDBC drivers in JasperReports Server:
    4. Save the file and restart JasperReports Server.

    JNDI Services on Apache Tomcat

    If you have trouble with a JNDI connection, you need to look at the JNDI definition for your database on your application server. This section gives common issues with JNDI definitions on Apache Tomcat connecting to MySQL. If you use a different application server or database server, refer to its documentation.

    A JNDI connection on Tomcat is defined in two different files. Make sure both have the following information:

    <tomcat>/webapps/jasperserver[-pro]/META-INF/context.xml
    <tomcat>/webapps/jasperserver-pro/WEB-INF/web.xml

    Also check the following points:

    Ensure the driver for your database connection is in the <tomcat>/lib folder.
    Ensure the database user has the privileges to run SELECT queries on the tables used in your reports. In some cases, additional permissions may be required to execute stored procedures, depending on your configuration and needs. For more information, see Database Permissions.
    If you installed JasperReports Server from a WAR file, Tomcat may have created a separate copy of context.xml in <tomcat>/conf/Catalina/Localhost/jasperserver-pro.xml. See the corresponding section in the troubleshooting appendix of the JasperReports Server Installation Guide.
    See the Apache Tomcat documentation for JNDI data sources.
    For Oracle databases, you may need to specify additional parameters in the context.xml file. For example, in order to support in Oracle, add the following line:

    JNDI Services on JBoss

    After defining JNDI Services on the JBoss application server, JasperReports Server does not automatically detect the new services. To use the new JNDI services as data sources in the server, follow these steps:

    1. Define and deploy a JNDI data source in the JBoss administrator console.

    Ensure the database user in your JNDI definition has the privileges to run SELECT queries on the tables used in your reports. In some cases, additional permissions may be required to execute stored procedures, depending on your configuration and needs. For more information, see Database Permissions.

    2. Modify the file <jboss>/webapps/jasperserver-pro/WEB-INF/web.xml to include a data source reference to this new JNDI service.
    3. Modify jboss-web.xml to include a reference to this data source.
    4. Because the deployment configuration files such as web.xml were modified, redeploy the JasperReports Server application.

    Now you can define JNDI data source in the repository, as described in JNDI Data Sources.

    JNDI Services on WebLogic

    Follow these steps to configure JasperReports Server to use JNDI data sources with WebLogic:

    1. Append the following definition to the <reference-descriptor> node of .../WEB-INF/weblogic.xml:
    2. Append the following definition to .../WEB-INF/web.xml:
    3. In the WebLogic Admin Console, create a JNDI data source, in this example its JNDI name would be TestDatabase.

    Ensure the database user in your JNDI definition has the privileges to run SELECT queries on the tables used in your reports. In some cases, additional permissions may be required to execute stored procedures, depending on your configuration and needs. For more information, see Database Permissions.

    4. Restart the jasperserver-pro instance using the WebLogic Admin Console.

    Creating a Data Source on SQL Server Using Windows Authentication

    If your database is Microsoft SQL Server and you use Windows Authentication (also called Integrated Security), use the following procedure to create a data source.

    1. Go to the download page for Microsoft SQL Server JDBC Driver 3.0.

    Do not use version 4.0 of this driver; it will not work.

    2. Download and run the self-extracting executable: 1033sqljdbc_3.0.1301.101_enu.exe
    3. Open the extracted folder sqljdbc_3.0enuauth, and then either the x64 or the x86 subfolder, depending on whether your version of Windows is 64-bit or 32-bit, respectively.
    4. Copy the file sqljdbc_auth.dll to the folder your app server automatically searches for DLLs.

    For Tomcat, this is the <tomcat>bin folder.

    5. Restart your app server.
    6. Log into JasperReports Server as an administrator.
    7. Select Create > Data Source from the main menu.
    8. Right-click the Data Sources folder and select Add Resource > Data Source from the context menu.
    9. In the Type field, select JDBC Data Source. The page refreshes to show the fields necessary for a JDBC data source.
    10. Enter a name and optional description for your data source.
    11. From the dropdown field, select com.microsoft.sqlserver.jdbc.SQLServerDriver.
    12. Enter the database hostname and database name of your SQL Server instance.
    13. In the URL field, add the following string to the end of the generated URL:

    ;integratedSecurity=true

    14. In the User Name field, enter any non-blank string you want, for example none.
    15. In the Password field, enter any non-blank string you want, for example none.
    16. Set the Time Zone and Save Location fields if necessary.
    17. Click Test Connection and verify that the connection works.
    18. Click Save to save the data source in the repository.

    Upgrading Bean Data Sources

    There was a change in the Spring configuration for JasperReports Server 6.0 which changes how some of the existing Spring beans are made accessible for use by other beans. This can break existing custom data sources. This change specifically affects beans which implement the interface ReportDataSourceServiceFactory.

    Prior to release 6.0, if code in JasperReports Server accessed a bean of this type, it would get the actual instance of the Spring bean as configured in the Spring XML file, and it could be cast to the concrete class. In 6.0 and later, these beans were intercepted in order to implement the profile attributes feature, and instead of seeing the actual instance, other code would see a dynamic proxy instead of the actual bean.

    Dynamic proxies are a Java feature which allows classes to be generated at run time that implement any interface that can be loaded on the classpath. The resulting object can be cast to any of those interfaces, but doesn't correspond to any concrete class. For more information:

    http://www.javaworld.com/article/2076233/java-se/explore-the-dynamic-proxy-api.html

    Since proxies can only represent interfaces, existing code that tries to cast the bean to a concrete class will break. Casting is usually done to get access to methods on a more specific class or interface. As long as the code is not casting the bean to a concrete class, it will work, so there are two ways to get around this problem:

    If the code needs to access methods on an existing interface, just do a cast to that interface, or inject the property using the existing interface, so no cast is needed.
    If the code needs to access methods that are not on an existing interface, simply create an interface with the methods needed, and have the target object implement that interface.

    For example, let's say you have a bean with id myBean that needs to access the jdbcDataSourceServiceFactory, configured as follows:

    Where myBean has the following Spring configuration:

    The following code worked before but will now cause an error:

    Because the first call is a method which is part of the ReportDataSourceServiceFactory, the cast is unnecessary; to fix it, just leave it out:

    In this example, JdbcReportDataSourceServiceFactory has a method called doSomethingElse(). This method is not part of any interface, but you can create an interface that includes it:

    JdbcReportDataSourceServiceFactory would need modification so that itimplements this new interface:

    You don't have to change the declaration in MyBean because Spring will generate a dynamic proxy implementing MyDSSF, but if you change the declaration, the code will be easier to understand because no casts will be necessary:

    SQLFeatureNotSupportedException Using TIBCO Drivers

    When you use the TIBCO driver to connect to any database onWebSphere 7 or 8.5, you may see errors such as the following after a query, for examplein the Ad Hoc editor. The query still performs correctly:

    This is a known error with the WebSphere Adapter(RRA) component. The error message appears in the log file, but it has no impact on functionality. The fix is currently targeted for inclusion in WAS fix pack 8.5.5.1. Please refer to IBM's Recommended Fixes for WebSphere Application Server page for delivery information.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...