2013-03-14 2 views
1

Birt를 처음 사용했습니다.Java 응용 프로그램에서 Birt 보고서로 연결 전달

내 자바 응용 프로그램에서 보고서에 대한 연결을 전달하기 위해 노력하고있어,하지만 난 오류 얻을 :이 만들고 발사보고 내 자바 코드가

The following items have errors:

ReportDesign (id = 1): + There are errors evaluating script "importPackage(Packages.it.lfiammetta.birt); var conn = new ReportRenderer(); reportContext.getAppContext().put("OdaJDBCDriverPassInConnection", conn);": Fail to execute script in function __bm_beforeOpen(). Source:

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

A BIRT exception occurred. See next exception for more information. Error evaluating Javascript expression. Script engine error: ReferenceError: "ReportRenderer" is not defined. (/report/data-sources/oda-data-source[@id="43"]/method[@name="beforeOpen"]#2) Script source: /report/data-sources/oda-data-source[@id="43"]/method[@name="beforeOpen"], line: 0, text: __bm_beforeOpen(). (Element ID:1)

입니다 :

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... 
     } 
} 

importPackage(Packages.it.lfiammetta.birt); 

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

나는 C를 설정합니다

이것은 내가 스크립트 'beforeOpen'데이터 소스에 쓴 코드는 성격.

사용중인 버트 버전은 4.2.1입니다.

미리 도움을 주셔서 감사 드리며 제 영어를 사과합니다. 나는 자바 코드에서 해당하고 있어요

답변

1

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

의 구현
관련 문제