2

私はバートが初めてです。

Java アプリケーションからレポートへの接続を渡そうとしていますが、次のエラーが発生します。

次の項目にエラーがあります:

ReportDesign (id = 1): + スクリプトの評価中にエラーが発生しました "importPackage(Packages.it.lfiammetta.birt); var conn = new ReportRenderer(); reportContext.getAppContext().put("OdaJDBCDriverPassInConnection", conn);":関数 __bm_beforeOpen() でスクリプトを実行できませんでした。ソース:

" + importPackage(Packages.it.lfiammetta.birt); var conn = new ReportRenderer(); reportContext.getAppContext().put("OdaJDBCDriverPassInConnection", conn); + "

BIRT 例外が発生しました。詳細については、次の例外を参照してください。Javascript 式の評価中にエラーが発生しました。スクリプト エンジン エラー: ReferenceError: "ReportRenderer" が定義されていません。(/report/data-sources/oda-data-source[@id="43"]/method[@name="beforeOpen"]#2) スクリプトソース: /report/data-sources/oda-data-source[ @id="43"]/method[@name="beforeOpen"]、行: 0、テキスト: __bm_beforeOpen()。(要素ID:1)

これは、レポートを作成して起動する私の Java コードです。

package it.lfiammetta.birt;

public class ReportRenderer {
        public void executeReport() {
                code...

                Map<String, Object> appContext = task.getAppContext();
                appContext.put("OdaJDBCDriverPassInConnection", myConnection);
                appContext.put("OdaJDBCDriverPassInConnectionCloseAfterUse", false);
                task.setAppContext(appContext);

                task.run();

                code...
        }
}

これは、スクリプト「beforeOpen」でデータソースを記述したコードです。

importPackage(Packages.it.lfiammetta.birt);

var conn = new ReportRenderer(); 
reportContext.getAppContext().put("OdaJDBCDriverPassInConnection", conn);

クラスパスを設定しました。

私が使用しているバートのバージョンは 4.2.1 です。

あなたの助けを前もって感謝し、私の英語についてお詫び申し上げます。

4

2 に答える 2

2

おそらくあなたはすでに問題を解決していますが、将来誰かがこれを探しているかもしれません. まず第一に、4.2.x バージョンでは、渡された接続に問題がありました。4.4.2 では同じエラーは見られませんでした。

ReportRendererその他、接続として行で渡そうとする理由がわかりません:

var conn = new ReportRenderer();
reportContext.getAppContext().put("OdaJDBCDriverPassInConnection", conn);

ここで渡されるオブジェクトは、オブジェクトである必要がありjava.sql.Connectionます。

したがって、

Map<String, Object> appContext = task.getAppContext();
appContext.put("OdaJDBCDriverPassInConnection", myConnection);
appContext.put("OdaJDBCDriverPassInConnectionCloseAfterUse", false);
task.setAppContext(appContext);

myConnectionの実装である限り、正しく見えますjava.sql.Connection

于 2015-07-02T14:22:12.560 に答える
2

私はJavaコードからそれをやっています(IJDBCParameters- 実際にはJDBC接続のパラメータ、名前で接続を探しています - OdaDataSourceHandle.getName()):

@SuppressWarnings("rawtypes")
private static void substituteJDBCConnections(IReportRunnable pReportRunnable) {
    final Map<String, IJDBCParameters> jdbcConnections = reportParameters.getJdbcConnections();
    if (jdbcConnections != null ){
        for (Iterator iter = pReportRunnable.getDesignHandle().getModuleHandle().getDataSources().iterator(); iter.hasNext();){
            // http://wiki.eclipse.org/Java_-_Execute_Modified_Report_(BIRT)
            Object element = iter.next();
            if (element instanceof OdaDataSourceHandle){
                OdaDataSourceHandle dsHandle = (OdaDataSourceHandle) element;
                String key = dsHandle.getName();
                if (key == null){
                    continue;
                }
                IJDBCParameters jdbcParams = jdbcConnections.get(key);
                if (jdbcParams == null){
                    continue;
                }
                try {
                    dsHandle.setProperty( "odaDriverClass", jdbcParams.getDriverName());
                    dsHandle.setProperty( "odaURL", jdbcParams.getConnectionString());
                    dsHandle.setProperty( "odaUser", jdbcParams.getUserName());
                    dsHandle.setProperty( "odaPassword", jdbcParams.getPassword());
                } catch (SemanticException e) {
                    throw new UncheckedException(e);
                }
            }
        }
    }
于 2013-03-15T09:25:57.130 に答える