Using CSV file as a data source via OOJDBC
JReport Designer supports CSV as a data source which can be accessed via OOJDBC.
Here is an example demonstrating how to import a CSV file to an ODF file generated by the Model Wizard. In this example, employee.csv in <install_root>\help\samples\OOJDBC
will be used. Store it to <install_root>\Demo\Reports\TutorialReports
first. Then follow the steps below to import the file to a catalog.
Importing the CSV file directly using the Model Wizard
To import the CSV file directly using the Model Wizard, take the following steps:
- Run ModelWizard.bat in
<install_root>\bin
. The Object Source Wizard will then appear.
- Select File > Import Text Files to bring up the Open Text Files dialog.
- Browse to the file employee.csv and then check the First Line Is Column Name checkbox.
- Click Open and the table Employee will now have been added to the Object Source Wizard.
- In the Object Source Wizard, click File > Save. You will then be prompted to save the ODF file. You should save it to
<install_root>\lib
or to the directory where the catalog will be located. Here, we save it as employee_csv.odf.
Note: The same ODF file cannot exist in both <install_root>\lib
and the directory where the catalog will be located.
Importing the ODF file into a catalog
To import the generated employee_csv.odf file into a JReport catalog, take the following steps:
- Start JReport Designer.
- Click File > Catalog Management > New Catalog.
- In the Input New Catalog Name dialog, specify the catalog name, the data source name and the path. The catalog should be located in the directory where you saved the ODF file. For example, if you saved the ODF file in
C:\odf
, the new catalog should be created also in C:\odf
.
- In the Catalog Browser, create a new JDBC connection in the Get JDBC Connection Information dialog as follows:
- Uncheck Use ODBC Data Source.
- Check the Driver checkbox, then enter com.jinfonet.jdbc.obj.ObjectDriver in the text field that follows.
- Type jdbc:jinfonet:object:@Filename in the URL text field. @Filename should be the ODF file name. In the example, it is jdbc:jinfonet:object:@employee_csv.
- Click OK to set up the connection.
- In the Add Table dialog, select the table Employee and click Add.
- Click Done to close the Add Table dialog.
Now, the table Employee will be added into the catalog. You can use it to develop reports as required.
Note: When you publish the catalog and its reports to JReport Server, whether the ODF file is located in <install_root>\lib
or in the directory where the catalog is located, it will be published to the path where the catalog is located on the server side.