views:

1149

answers:

1

Hi

Since I'm using a newer release of JRC a replacement of database connection information do not work any more. I've no idea why. This code worked with a JRC version from last autumn (unfortunately I don't have a release number):

ReportClientDocument doc = new ReportClientDocument();
doc.open("report.rpt");

IDatabase db = null; // get sub report database

// we'll overwrite the database connection information within
// the chosen report.
Map<String, String> bag = new HashMap<String, String>();
bag.put("Connection URL", "jdbc:oracle:thin:@LOCALHOST:1521:DATABASENAME");
bag.put("Server Type", "JDBC (JNDI)");
bag.put("Database DLL", "crdb_jdbc.dll");
bag.put("Database Class Name", "oracle.jdbc.driver.OracleDriver");

for (Object table : db.getTables()) {
  updateTable(dhb, dc, (ITable)table, bag);
}

...

private void updateTable(DatabaseController dc, ITable table, 
    Map<String, String> bag) throws ReportSDKException {

  ITable t = (ITable)table.clone(true);

  LOGGER.debug(t.getName());
  LOGGER.debug("1: " + t.getConnectionInfo().getAttributes());

  IConnectionInfo connInfo = t.getConnectionInfo();
  connInfo.setUserName("UserX");
  connInfo.setPassword("xxxxx");
  connInfo.setAttributes(new PropertyBag(bag));
  // LOGGER.debug("ConnInfo Kind: " + connInfo.getKind());
  t.setConnectionInfo(connInfo);
  // t.setName(((ITable)table).getName());
  t.setQualifiedName("UserX" + "." + table.getName());
  dc.setTableLocation(table, t);

  LOGGER.debug("2: " + t.getConnectionInfo().getAttributes());

}

I get this error: 'Fehler bei der Suche nach JNDI-Namen (UserY)'. That means JRC can not find given JNDI name.

Does anyone knows some changes between those JRC releases? And does anyone knows a solution?

Thank you in advance.
Regards
Thomas

+1  A: 

I've found the problem and a workaround after a long debugging session.

// incomplete code example

for(Object table : db.getTables()) {

  ITable t = (ITable)((ITable)table).clone(true);
  System.out.println(t.getName());

  // modifying t, bag is an existing instance of class PropertyBag
  t.getConnectionInfo().setAttributes(bag);

  // dc is an existing instance of DatabaseController
  dc.setTableLocation((ITable)table, t)

}

db.getTables() contains 3 tables A, B and C. If we'll run the code above System.out prints A, A, B to the console.

If we're going to comment dc.setTableLocation((ITable)table, t) out. A, B, C will be printed. I assume that dc.setTableLocation((ITable)table, t) modifies internally the list of tables.

We're using following workaround:

// incomplete code example

// WORKAROUND CODE
Map<ITable, ITable> oldNewMap = new HashMap<ITable, ITable>();

for(Object table : db.getTables()) {

  ITable t = (ITable)((ITable)table).clone(true);
  System.out.println(t.getName());

  // modifying t, bag is an existing instance of class PropertyBag
  t.getConnectionInfo().setAttributes(bag);

  // WORKAROUND CODE
  oldNewMap.put((ITable)table, t);

}

// WORKAROUND CODE
for (Entry<ITable, ITable> e : oldNewMap.entrySet()) {
  dc.setTableLocation(e.getKey(), e.getValue());
}

I hope somebody will save time and money with this workaround. ;-) I posted it to the official forum as well.

Forum: Java Development - Crystal Reports

Zubi