You are on page 1of 4

How to Connect to a Database Or a Data Source using iReport

To connect to a data source using iReport you need to configure the Data source. To do that go to Data Connection/Data Sources From the Main Menu items. You would get the Connection/Data Sources Window. Click New

Most of the time you would be using a JDBC data source or a Hibernate Connection. For the sake of the first report we will look at the much simpler and common way of using a JDBC

connection. To configure a JDBC connection click JDBC Connection and click Next

To connect to a MySQL or a Oracle Database first you need to define a Driver. While iReport comes with a lot of dirvers it for some strange reason does not include an Oracle Driver. Connecting to MySQL Set your server path and data base name in the JDBC URL Wizard. Then Click Wizard and it will automatically set your JDBC URL. Make Sure you have selected the com.mysql.jdbc.Driver and Type the User name and password to the database and click Test. Your Data base connection should be working properly. If not check your MySQL database URL is correct or/and the database server is running properly. If the test is Successful click Save. Connecting to Oracle Database. As I mentioned above iReport does not have a Oracle JDBC driver included. To Connect to Oracle you need to have a Oracle JDBC Driver compliant with your Oracle Version. They can be found here. Ive used ojdbc14.jar with Oracle 9i and 10i. Place the Oracle JDBC Driver in your lib directory. If you have installed using the default settings this would be in the c:/Programfiles/jaspersoft/ireport2.0.5 directory Set your Server Path and the database name in the JDBC URL wizard. Then click Wizard button and the Database URL would be set WITH THE PORT 1521. If you are not using that simply modify it to the port u are using in the JDBC URL Field. Type the User name and password to the database.

Set the JDBC Driver Field to oracle.jdbc.driver.OracleDriver and click test. If not successful check your username/password and Database URL and Try again. After the test is successful click Save. Now you are ready to start designing a report. UPDATE on 08 Dec 2010 A Better Example Through Comments (@author prakash)
Steps to set the Classpath for iReport: 1) go to "Tools / Options" menu and select iReport 2) verify that database JDBC driver is present: - Choose "Classpath" tab - Click "Add JAR" and then locate the mysql.jdbc.Driver - Click "OK" 3) click "Connections / Datasources" icon in toolbar 5) click "New" and set up a "Database JDBC Connection" using driver from step 2 6) click "Test" to verify the data source works correctly 7) click "Save" to save the data source

Connecting iReport to an Oracle Datasource


The following are steps that can be followed to set up a data source within iReport to connect to an Oracle database: Note:These instructions will work for iReport version 3.1 and greater. 1. Download the JDBC driver (ojdbc-[your version].jar) from Oracle @ http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html 2. in iReport, go to the following menu Window =>Services

3.

Expand the Database tree that shows in the Services window and right-click on the Drivers folder and select "New Driver..."

4.

Add the jar file; Give it a name i.e. "Oracle Thin" and click OK

5.

Right Click on the new "Oracle Thin" driver that appears in the Services window and selected "Connect Using..."

6.

Set up the database connection - as an example, you might use "jdbc:oracle:thin:@remotehost:1521:orcl", your username and password - and click ok

7.

Add a new datasource using the NetBeans Database JDBC connection - the new connection defined should be in the dropdown

8.

Open the report wizard and you are on your way....

You might also like