Crystal Reports for Eclipse Developer Guide

To change a persistent data source

Persistent data sources provide data for a report that exists both within and beyond runtime scope. The recommended way to change your persistent data source is to use the com.crystaldecisions.sdk.occa.report.application.DatabaseController.replaceConnection method.
Each table used by a report requires a properly configured data source connection, represented by a IConnectionInfo object. The replaceConnection method automatically propagates your new data source connection to all tables in the report that use the old connection.
Note: If instead you want to change the connection for a particular table, you can do so using one of the setTableLocation methods available in the DatabaseController class.
The following steps show how to change a single data source connection for all tables in a report to a new ODBC connection. However, the fundamental workflow described can be applied to any type of data source.
  1. Retrieve the DatabaseController object.
    DatabaseController databaseController = rcd.getDatabaseController();
  2. Retrieve the collection of all data source connections in the report.
    ConnectionInfos connectionInfos = (ConnectionInfos)databaseController.getConnectionInfos(null);
  3. Call the getConnectionInfo method of the ConnectionInfos collection to retrieve a single connection.

    Note: This example assumes the report has a single data source. Different tables in your report may have different data source connections, and you can change the connection for each in the collection as necessary.
    IConnectionInfo oldConnectionInfo = connectionInfos.getConnectionInfo(0);
  4. Create a new ConnectionInfo object to represent the new data source connection.
    IConnectionInfo newConnectionInfo = new ConnectionInfo();
    newConnectionInfo.setKind(ConnectionInfoKind.SQL);
  5. Create a new PropertyBag object and add the custom logon properties, as well as the default connection properties for the new data source.
    PropertyBag newProperties = new PropertyBag();
    newProperties.putStringValue("DSN", "Xtreme Sample Database 2005");
    newProperties.put("UseDSNProperties", false);
    newProperties.putStringValue(PropertyBagHelper.CONNINFO_SERVER_NAME, "Xtreme Sample Database 2005");
    newProperties.putStringValue(PropertyBagHelper.CONNINFO_SERVER_TYPE, "ODBC (RDO)");
    newProperties.putStringValue(PropertyBagHelper.CONNINFO_DATABASE_DLL, "crdb_odbc.dll");
  6. Call the setAttributes method of the IConnectionInfo object to set the connection properties of the new data source.
    newConnectionInfo.setAttributes(newProperties);
  7. Set the user name and password credentials for the new data source.
    newConnectionInfo.setUserName("username");
    newConnectionInfo.setPassword("password");
  8. Call the replaceConnection method of the DatabaseController object to change your old data source connection to the new connection.
    You must pass in an integer value as the last parameter, such as DBOptions._useDefault (0), rather than an actual DBOptions object such as DBOptions.useDefault.
    Note: The replaceConnection method throws a ReportSDKServerException exception.
    try 
    {
        databaseController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, DBOptions._useDefault);
    }
    catch (ReportSDKException error) 
    {
        System.out.println(error.getSDKError());
    }
Example: 
The following code changes a single data source connection for all tables in a report to a new ODBC connection.
void changeDataSource(ReportClientDocument rcd)
{ 
  DatabaseController databaseController = rcd.getDatabaseController();
  ConnectionInfos connectionInfos = (ConnectionInfos)databaseController.getConnectionInfos(null);
  IConnectionInfo oldConnectionInfo = connectionInfos.getConnectionInfo(0);
  IConnectionInfo newConnectionInfo = new ConnectionInfo();
  
  newConnectionInfo.setKind(ConnectionInfoKind.SQL);

  PropertyBag newProperties = new PropertyBag();
  newProperties.putStringValue("DSN", "Xtreme Sample Database 2005");
  newProperties.put("UseDSNProperties", false);
  newProperties.putStringValue(PropertyBagHelper.CONNINFO_SERVER_NAME, "Xtreme Sample Database 2005");
  newProperties.putStringValue(PropertyBagHelper.CONNINFO_SERVER_TYPE, "ODBC (RDO)");
  newProperties.putStringValue(PropertyBagHelper.CONNINFO_DATABASE_DLL, "crdb_odbc.dll");
  
  newConnectionInfo.setAttributes(newProperties);
  newConnectionInfo.setUserName("username");
  newConnectionInfo.setPassword("password");
  
  try 
  {
    databaseController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, DBOptions._useDefault);
  }
  catch (ReportSDKException error) 
  {
    System.out.println(error.getSDKError());
  }
}



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/