Sunday, April 27, 2008

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. I’ve 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


27 comments:

Ika said...

Hi,

I've placed ojdbc14.jar and classes12.jar into ireport lib directory. but i still can't connect to the database. sometimes it told: network adapter can't establish connection. sometimes: connection refused. could you help me, please?

Thanks.

Ika

peter said...

how can i connect sql server.. pls anyone tell me..

Anonymous said...

I too am trying to connect with SQL Server

My recommendation is that this should be included with the release package jDBC?, MS JDBC Driver ?

All this talk of Ants, TomCats and Jakarta is just confusing me :)

I downloaded
http://freefr.dl.sourceforge.net/sourceforge/jtds/jtds-1.2.2-dist.zip

Installed this into a folder & it worked OK for me specifying server / port/ db (my Port was 1434)

Good luck !

Anonymous said...

How to connect ireport using postgressgl pls helpppppppppppppppppppppppp,,,,,,,,,,,,

Anonymous said...

please in the above article, you have referred to only JDBC connection, please write something about how to create hibernate connection

Anonymous said...

is ireport connect remotly with database i try but i failed can any one help me
thanks;

prakash said...

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

Anonymous said...

the step on prakash said... on January 12, 2010 worked!

Anonymous said...

Thanks prakash. It was very useful information. Acromantula, please remove your explanations on how to connect to a database with ireport and expand prakash's idea because it's clearly more intuitive.

Anonymous said...

Thanks it is useful but during test for database connection i am getting nested exception. what does it mean?

Anonymous said...

i tried classe12.jar ojdbc6.jar

no way to connect to an oracle database (8.1.7)

venu said...

How to connect the spring hybernate .step by step explain

Anonymous said...

How to connect netezza database through i report

Anonymous said...

to get connection to oracle 8.1.7 works put just the classe12.jar and drop ojdbc6.jar from /tomcat/lib

it works for me

bye

Anonymous said...

Sres. Yo tuve este problema por mucho tiempo, sin lograr resolverlo. Pero el día de hoy, desinstale el iReport y lo volvi a instalar, a la primera funciono, momento despues configure otras cosas y mi sorpresa...!!! dejo de funcionar nuevamente. Retrocediendo con lo que habia echo, despues de la instalación me di cuenta que al configurarle el proxy manualmente al iReport, deja de resolver la direccion del server de BD (Ip o hostname). Solo le quite el proxy nuevamente y tengo una conexión estable. Por si a alguien le sirve esta solucion.

Anonymous said...

i still dont get it.. how to connect to sql developer?

Anonymous said...

How can I add new driver to connect to HiRDB .how can I configure it

Anonymous said...

Hi,

When i try to establish an oracle connection having a service name as opposed to a SID iReportDesigner is throwing invalid connection format error.
Can you please tell me how to get around this?

Many Thanks in advance,
Manju

as said...

hello sir,
I done all the things that u told but while connecting to database i got error

SQL problems: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869568)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
jdbc:oracle:thin:@localhost:1521:EMPLOYEES
plz help me.

Anonymous said...

Thanks°°°

Tarun said...

Thnx ....Its working...

Carola Lagos said...
This comment has been removed by the author.
Anonymous said...

Hi, please how can I connect iReports to a remote mysql database, please help

Anonymous said...

Thank You very much for this article
-Shrikant Pande

abc said...

SQL problems: The Network Adapter could not establish the connection
jdbc:oracle:thin:@localhost:1521:thacam

m getting above error ...can u help?

Anonymous said...

i just want to ask if, do i need to have an internet connection while performing the connection on database?? thankyou and godbless ^_^

Chaitali Shekhar said...

java.sql.sqlexception io exception the network adapter could not establish the connection oracle 10g

Post a Comment