2009-01-26 5 views
1

Étant donné que j'utilise une version plus récente de JRC, le remplacement des informations de connexion à la base de données ne fonctionne plus. Je ne sais pas pourquoi. Ce code a travaillé avec une version JRC de l'automne dernier (malheureusement je n'ai pas de numéro de version):Remplacer une connexion de base de données pour les sous-rapports avec JRC

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()); 

} 

Je reçois cette erreur: « Fehler bei der Suche nach JNDI-Namen (UtilisateurY) '. Cela signifie que JRC ne peut pas trouver le nom JNDI donné.

Est-ce que quelqu'un connaît des changements entre ces versions du JRC? Et quelqu'un connaît une solution?

Répondre

1

J'ai trouvé le problème et une solution de contournement après une longue session de débogage.

// 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() contient 3 tables A, B et C. Si nous courons le code ci-dessus System.out A imprime, A, B à la console.

Si nous allons commenter dc.setTableLocation((ITable)table, t). A, B, C seront imprimés. Je suppose que dc.setTableLocation((ITable)table, t) modifie en interne la liste des tables.

Nous utilisons solution suivante:

// 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()); 
} 

J'espère que quelqu'un va gagner du temps et de l'argent avec cette solution de contournement. ;-) Je l'ai également posté sur le forum officiel.

Forum: Java Development - Crystal Reports

Questions connexes