#### An illustrative example

You are provided with a sample program that demonstrates how to use the Catalog API to create or modify a catalog - TestCatalogAPI.java that is located in `<install_root>\help\designer\samples`.

Here, TestCatalogAPI.java has been used as an example to explain how the methods work in the Catalog API.

- Creating an Designer object
  `Designer dr = new Designer(".\\","demo.cat");`

  If the catalog named demo.cat exists, it will be opened. Otherwise it will be created.

- dr.setUserInfo("UID","XXXXXXXXXXX")
  Reminds you to set the license key for Designer API.
- Getting a CatalogAPI instance
  `CatalogAPI cat = dr.getCatalogAPI();`
- Creating a connection
  `ConnectionHandles = cat.insert(true,"jinfonet","Accessdbase","jinfonet",null);`
- Inserting objects into a catalog
  For example, insert a table named Customer:

  `tablehandles = cat.insert(null,null,"Customer",cat.TABLE);`

- Inserting a formula named "total"

      String formulahandles=cat.insert("total",cat.FORMULA);
      FormulaInfo formulainfo=new
      FormulaInfo("total","total formula","@\"Unit Price\" * @Quantity - @Discount");
      cat.set(formulahandles,formulainfo);

- Importing an SQL file
  `cat.insert("SQL1","C:\\JReport\\Designer\\help\\designer\\samples\\sqlfile.txt");`
- Saving
  `cat.save();`
- Compiling and running the demo program
  To compile and run the demo program, you should add the required classes to the class path.

  In the following example, we assume that all the classes used in the demo are included in `C:\test\classes`, for example, the classes for creating a catalog. After running the program, a new catalog file Tutorial.cat will be created in `C:\JReport\Designer\Demo\Reports\APITutorial`. Be sure to create this empty directory first.

      C:\JReport\Designer\help\designer\samples>javac
      -classpath "C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\test\classes"
      TestCatalogAPI.java

      C:\JReport\Designer\help\designer\samples>java
      -classpath "C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\log4j-1.2.8.jar;
      C:\JReport\Designer\help;C:\test\classes"
      -Dreporthome=C:\JReport\Designer
      TestCatalogAPI C:\JReport\Designer\Demo\Reports\APITutorial
      APITutorial C:\temp\api.log