We will introduce data connection of FineReport reporting tool in this article.Data connection is stored in the project. Only when the user operates the database, these connections will be activated.

1. Overview

Before making reports, it is required to define the data sources. In common user system, data are saved and updated in database. Reports are made with database data and their contents will be updated with the renewal of database.

This is naturally supported by FR. Define the database to be connected in Designer > Define Data Connection. You can custom query statements to query the required data, so as to make reports, as shown below:

Data connection is stored in the project. Only when the user operates the database, these connections will be activated.

One report project can define several database connections. All information is saved in the configuration file of %FR_HOME%\WebReport\WEB-INF\resources\datasource.xml.

Database can be connected via JDBC, JNDI, SAP, XMLA and FineBI. Only when the report executes the database, these connections will be activated.

Note: XMLA and FineBI are connected to multi-dimensional database, where, FineBI is the database that connects to another BI product of FineReport reporting software.

2. Difference between JDBC and JNDI

2.1 JDBC database connection

JDBC (Java Database Connectivity) is a Java API to execute SQL statements and provides uniform access to a variety of relational databases. The JDBC database connection method will be described below.

2.2 JDBC database connection

JNDI (Java Naming and Directory Interface) is an API designed with applications and provides a universal and uniform interface for developers to find and access various naming and directory services. Similar to JDBC, JNDI is also constructed in an abstraction layer.

2.3 JDBC and JNDI database connections, which one is superior

When JNDI is used to connect a data source, e.g., test, all databases connected by this data source are defined in the application server. Therefore, JNDI connection data source is not required to consider the specific database backstage. What’s the JDBC driver? What’s the JDBC URL format? What’s the user name and password to access the database? There is even no database connection pool or connection management. These problems are delivered to the J2EE container for configuration and management. You just need to refer to those configurations and managements.

After report deployment, if the related parameters in the database are changed, you are only required to change the JDBC parameters in the configuration files again. As long as the data source name remains unchanged, there is no need to change the data connection. Thus, it can be seen that JNDI avoids close coupling between the reports and the databases and shares the server connection pool with the project, making the application easy for deployment and deployment.

JDBC establishes a direct connection to the physical database with fast speed. However, it is complicated if used in programs since every connection requires certain code and the connection to database has to be switched off manually.