#### 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\samples\APICatalog`.

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

- Creating a Designer object
  `DesignerUserInfo userInfo=new DesignerUserInfo("UID", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
  desg = new Designer(path, catName, userInfo);`

  If the catalog named catName (MyReports.cat) exists, it will be opened. Otherwise it will be created.

- Getting a CatalogAPI instance
  `CatalogAPI cat = dr.getCatalogAPI();`
- Creating a connection
  `ConnectionInfo info = new ConnectionInfo("sa", "");
  String con = cat.insert("", false,"Jinfonet demo", "demo db",
  "jdbc:hsqldb:C:\\JReport\\Designer\\Demo\\db\\JRDemo", "org.hsqldb.jdbcDriver", info);`
- Inserting objects into a catalog
  For example, insert a table named Customers:

  `tb.addTable("", null, "PUBLIC", "CUSTOMERS", "Customers");`

- 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","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.

  After running the program, a new catalog file MyReports.cat will be created in `C:\JReport\Designer\Demo\MyReports`. Be sure to create this empty directory first.

  `C:\JReport\Designer\help\samples\APICatalog>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\samples\APICatalog>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 -path=C:\JReport\Designer\Demo\MyReports -catalog=MyReports.cat -log=C:\JReport\Designer\logs\designer.log`