Example 1: Developing reports from flat file UDS

This example is a plain text file AddressesList.txt (available in <install_root>\help\samples\APIUDS\txtUDS), which contains data information in a dummy table:

Laurena    Croft    34826 Atwood St.     New York City    NY    10004     USA...
Jonathan    Hopkins    5062 Brandon Green Ave.     Minneapolis    MN    55402     USA...
Jeremy    Miner    9283 Cherry Leaf Lane     Palo Alto    CA    94303     USA...
....

You will notice that each line sequentially records the name, address, state, region, zip code, country, e-mail address and other information. In this example, you will be shown how to add an UDS using the data stored in a formatted text file. You can modify this example to meet your requirements.

Compiling and running the Address UDS

There are three classes used in this example and their source code are AddressListUDS.java, AddressListResultSet.java and AddressListResultSetMetaData.java. The data file is AddressesList.txt. All these files are available in <install_root>\help\samples\APIUDS\txtUDS.

If you use your own UDS classes, you must be sure that the class files can be found when running. So, make sure that the directory is classpath/package name. For this demo's UDS classes, the classes belong to a package named help. Copy the above necessary files to <install_root>\help, and add the additional entry to the ADDCLASSPATH variable of the batch file setenv.bat in <install_root>\bin.

For example, on Windows, if you installed JReport Designer into the default directory C:\JReport\Designer,

  1. Copy the above necessary files to C:\JReport\Designer\help.
  2. Compile the Java files.

    javac -classpath "C:\JReport\Designer\lib\JREngine.jar" Address*.java

  3. Add the additional entry into the ADDCLASSPATH variable of setenv.bat in C:\JReport\Designer\bin.

    set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;C:\JReport\Designer\help;

Adding the Address UDS to a catalog

After compilation, you can now add the UDS to a JReport catalog.

  1. Start JReport Designer with the batch file you just modified.
  2. Open an existing catalog.
  3. In the Data tab of the Catalog Browser, right-click the data souce to which the UDS is to be added, then select Add User Defined Data Source from the shortcut menu.
  4. In the Add User Defined Data Source dialog, enter the following information:
  5. Click OK to add the UDS.
Developing a report with the Address UDS

Now that the Address UDS has been successfully added to the catalog, you can use it to develop reports as required. For details about how to create reports in JReport Designer, see Creating a page report.