How to set a datasource for a BIRT report programmatically?

后端 未结 5 993
借酒劲吻你
借酒劲吻你 2021-02-04 08:46

I have a BIRT report which connects to our test database. In the productive environment I would like to supply a datasource which is provided by the container through jndi.

5条回答
  •  难免孤独
    2021-02-04 09:17

    This worked for me. I got the context and from context got the dataSource and passed the connection to Birt report like below

      Context initialContext = new InitialContext();
         if ( initialContext == null){
         System.out.println("JNDI problem. Cannot get InitialContext.");
            }
            DataSource datasource = (DataSource)initialContext.lookup("java:/datasources/SAMPLE");
         task.getAppContext().put("OdaJDBCDriverPassInConnection", datasource.getConnection());
    

提交回复
热议问题