A JDBC connection allows you to use a relational DBMS (or, in general, whatever databases are accessible through a JDBC driver) as a data source. To set a new JDBC connection, click the New button in the Connections/Datasources dialog (shown earlier in “DataAdapter Wizard”) to open the interface for creation of a new connection (or data source). From the list, select Database JDBC connection to open the Data Adapter dialog.
Configuring a JDBC Connection |
First, name the connection (use a significant name like Mysql – Test). Jaspersoft Studio will use this name to refer to this connection.
In the JDBC Driver field, specify the JDBC driver to connect to the database. The combo box proposes the names of the most common JDBC drivers .
JDBC Drivers List |
If a driver is displayed in red, the JDBC driver class for that driver is not present in the classpath and you must obtain and install the driver before using it. See Working with Your JDBC Connection.
Thanks to the JDBC URL Wizard, you can automatically construct the JDBC URL to use the connection to the database by inserting the server name and the database name in the correct text fields. Click the Wizard button to create the URL.
Enter a username and password to access the database. A check box enables you to save the password.
Jaspersoft Studio saves passwords in Eclipse secure storage. In some cases, this can cause problems when trying to test and save data adapters. For more information, refer to our Eclipse Secure Storage in Jaspersoft Studio Community wiki page. |
If the password is empty, it is better if you specify that it be saved.
After you've inserted all the data, click the Test button to verify the connection. If everything's okay, you'll see this message:
Test Confirmation Dialog |
When tests fails, the most common exceptions are:
• | A ClassNotFoundError was thrown. |
• | The URL is not correct. |
• | Parameters are not correct for the connection (database is not found, the username or password is wrong, etc.). |
ClassNotFoundError
The ClassNotFoundError exception occurs when the required JDBC driver is not present in the classpath. For example, suppose you want to create a connection to an Oracle database. Jaspersoft Studio has no driver for this database. If you mistakenly choose the oracle.jdbc.driver.OracleDriver driver, when you test the connection,you'll see the ClassNotFoundException, as shown in “ClassNotFoundError exception”.
ClassNotFoundError exception |
You'll need to add the JDBC driver for Oracle to the classpath. As Jaspersoft Studio uses its own class loader, it's enough add the ojdbc14.jar file to the Jaspersoft Studio classpath, which is defined in your Eclipse project; the same can be done for directories containing classes and other resources. To edit the classpath, click Project > Properties > Java Build Path>Libraries, and click Add JARs. If you need to use the driver only for this data adapter, you can instead add the driver on the data adapter's Driver Classpath tab.
URL Not Correct
If a wrong URL is specified, you’ll get an exception when you click the Test button. You can find the exact cause of the error using the stack trace provided in the exception.
In this case, if possible, it is better to use the JDBC URL Wizard to build the JDBC URL and try again.
Parameters Not Correct for the Connection
If you try to establish a connection to a database with the wrong parameters (for example invalid credentials or inaccessible database), the same database returns a message is fairly explicit about the reason behind the failure of the connection.
Recommended Comments
There are no comments to display.