Chapter 5. Adding a Relational Data Source

In this chapter, we will create a copy of the report created in the previous chapter and modify it so that it takes its data from a relational source. We will explain what JDBC is, what a JDBC driver is, and how it is used.

The topics we will be covering in the chapter include the following:

  • Downloading the JDBC driver for MySQL and copying it inside Pentaho Report Designer (PRD)
  • Using the UI to create/edit JDBC-type data sets and creating a JDBC connection to our sakila database, with its corresponding SQL query
  • Modifying the following sections: Report Header, Group Header, Details Header, and Details Footer; we will configure the last two to be repeated on each page
  • Deleting certain objects from the report, adding some new ones, and modifying others so that they all correspond to our new data source
  • Aggregation functions, explaining the most used ones; we will add a new function into our report and use its output in order to modify the style of a message
  • Understanding and modifying the charset of our report

As an extra, we will invite you to create your own report from the ground up, as well as give you a few tips to assist you in its creation.

Learning about JDBC driver

Java Database Connectivity (JDBC) is an Application Programming Interface (API), which defines how a client should access and interact with a database from Java. Each provider (IBM, Oracle, Sun, Microsoft, and others) implements the mechanism (the "How To") for its own product, allowing the client not to be bothered with the details of each implementation and worrying only about its interface. In Java slang, this is known merely as a controller or JDBC driver.

Note

A JDBC driver, generally speaking, consists of one or various files with a .jar extension, which must be copied on a certain path (Java CLASSPATH, that is) so that applications can make use of it instead.

In order for a JDBC driver to be used, Java programs require the following information:

  • URL: This is a string that specifies, among other things, the protocol, location of the server, port, and name of the database.
  • Driver: This is the name of the class that implements the java.sql.Driver interface.
  • User: This is the user with the necessary privileges on the database engine (this parameter might be optional depending on the case).
  • Password: This is the password corresponding to the user (this parameter might also be optional).

In some cases, the inclusion of the user and password is supported within the URL, so we only need to define the URL and Driver parameters.

The syntax to indicate the URL and driver class name should always be present in the implementation documentation of each provider.

For example, in the case of MySQL, the information regarding the implementation can be found in the following web page:

http://dev.mysql.com/downloads/connector/j/5.1.html

The implementation details are as follows:

  • Driver: com.mysql.jdbc.Driver
  • URL: jdbc:mysql://localhost:3306/MyDataBase
  • Protocol: jdbc:mysql
  • Name server: localhost (local address)
  • Port: 3306 (default port)
  • Database: MyDataBase
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset