Using the Catalog Bean

After making the required preparations, you can now use the Catalog Bean to perform tasks.

Creating a catalog

The method newCatalog creates an empty catalog according to the catalog name that is set in catName, and saves it to disk.

When creating a new catalog, the directory of the catalog name should exist and contain no catalog files. You should make sure of this before you start creating the new catalog.

Try
{ 
    jrCatalog.setCatName("c:\\a.cat"); 
    newCatalog(); 
} 
catch(JRCatalogException e) 
{
    System.out.println(e);
}
Loading an existing catalog

The method loadCatalog is used to load a catalog according to the catalog name that is set in catName.

try
{
    jrCatalog.setCatName("c:\\a.cat");
    loadCatalog();
} 
catch(JRCatalogException e) 
{ 
    System.out.println(e); 
}
Manipulating a catalog

A catalog can be manipulated by the actions of adding, deleting and editing of objects within it. A catalog contains many kinds of objects. These objects include connections, tables, views, file queries, stored procedures, queries, WHERE portions, formulas, summaries and parameters.

For example, you can modify the connection, the name, the URL, the user, the password and the driver.

try 
{ 
    ConnectionDesc conDesc=new ConnectionDesc(); 
    conDesc.strName="Demo"; 
    conDesc.strURL="jdbc:oracle:thin:@myhost:1521:orcl"; 
    conDesc.strUser="system"; 
    conDesc.strPassword="manager"; 
    conDesc.strDriver="oracle.jdbc.driver.OracleDriver"; 
    jrCatalog.modifyConnection(conDesc);
} 
catch(JRCatalogException e)
{ 
  System.out.println(e);
}
Getting information

You can get information about objects in a catalog via some methods.

For example, you can get the connection information via the method getConnectionDesc().

Try 
{ 
    ConnectionDesc conDesc = bean.getConnectionDesc();
} 
catch(JRCatalogException e) 
{ 
    System.out.println(e); 
}
Saving a catalog

Changes to a catalog are saved to a disk only when the method saveCatalog is used.

Try 
{ 
    jrCatalog.saveCatalog(); 
}
catch(JRCatalogException e)
{ 
    System.out.println(e); 
}
Handling exceptions

When an error occurs, the JRCatalogException is thrown out. Your program will catch the exception and handle the error.

The exception describes the error code and detailed message as follows: