Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » how to set data source connection string at runtime
how to set data source connection string at runtime [message #630691] Mon, 04 October 2010 15:14 Go to next message
Dave Missing name is currently offline Dave Missing nameFriend
Messages: 20
Registered: October 2010
Junior Member
Hello, I am new to Birt, and need some help.

1. I like to embed Birt into JSF web application. I can design a report using eclipse, but JDBC connection info is known at runtime. How to set JDBC connection info (connection string, username, password, etc) when running report engine?

2. Similarly, how to set SQL parameters at runtime?

3. Is there a way for BIRT to use query built by Hibernate Criteria API?

Thanks for help.

Dave
Re: how to set data source connection string at runtime [message #630710 is a reply to message #630691] Mon, 04 October 2010 15:49 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Dave,

1 - There are a lot of different ways to do this if you are using the
API. You can pass them in as report parameters or in a session object.
You can then use the property binding feature within the dataset
editor to set them based on how you pass them in. You can also set them
in report script. For example assume you pass them is a parameter like

//this is a report parameter
task.setParameter("myrunitmeconnectionurl",yourconnectionurl);

Then in the beforeOpen script of the dataset you would set it like:
this.setExtensionProperty("odaURL",params["myruntimeconnectionurl "].value);

You can also set it in the property binding tab of the datasource
editor. Just use the expression params["myruntimeconnectionurl"].value

You can pass in the connection object as well. This will ignore all
design time settings.

task.getAppContext().put("OdaJDBCDriverPassInConnection", myconn);
//specify whether to close connection after use or not
task.getAppContext().put("OdaJDBCDriverPassInConnectionCloseAfterUse ",
true);

2 - In the dataset editor you can set up dataset parameters by using the
? in the sql editor. For example select * from orders where ordernumber = ?

This will create a dataset parameter. You can set the default value for
this parameter or create a report parameter and link the dataset to the
report parameter(data set editor parameters tab). If you link it to a
report parameter you can just use the task and set the report parameter
which will automatically pass to the dataset parameter when the report
is executed.

3 - Jboss provides a Hiberate ODA to run HQL instead of using the BIRT
SQL datasource. Is this what you want?

Jason

On 10/4/2010 11:14 AM, Dave wrote:
> Hello, I am new to Birt, and need some help.
>
> 1. I like to embed Birt into JSF web application. I can design a report
> using eclipse, but JDBC connection info is known at runtime. How to set
> JDBC connection info (connection string, username, password, etc) when
> running report engine?
>
> 2. Similarly, how to set SQL parameters at runtime?
>
> 3. Is there a way for BIRT to use query built by Hibernate Criteria API?
>
> Thanks for help.
>
> Dave
Re: how to set data source connection string at runtime [message #630793 is a reply to message #630710] Tue, 05 October 2010 03:23 Go to previous messageGo to next message
Dave Missing name is currently offline Dave Missing nameFriend
Messages: 20
Registered: October 2010
Junior Member
Hi Jason, thanks for your detail help.

For the number 3, all our queries are dynamically built by Hibernate Criteria API, not HQL. I am wondering if Birt can use it as data source/data set. I looked at Scripted data source. Is Birt JavaScript is the same one understood by web browser such as IE?

How/where to put the Scripted data source code when I deploy the report design to JBoss where I run the web application?

I need to write the script using Java and references classes in the jars under WEB-INF of the web application. When and how does the script get compiled? Only JRE is installed on target machine.

Thanks,
Dave
Re: how to set data source connection string at runtime [message #630940 is a reply to message #630793] Tue, 05 October 2010 15:39 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Dave

A scripted data source can be written in Java or JavaScript and it is
executed server side not client side so the browser does not matter.

If you are using the viewer there is a scriptlib directory that you
should copy your jars to. This directory is also configurable in the
web.xml

The classes are compiled like any other web app so this should not be an
issue.

Jason

On 10/4/2010 11:23 PM, Dave wrote:
> Hi Jason, thanks for your detail help.
>
> For the number 3, all our queries are dynamically built by Hibernate
> Criteria API, not HQL. I am wondering if Birt can use it as data
> source/data set. I looked at Scripted data source. Is Birt JavaScript is
> the same one understood by web browser such as IE?
>
> How/where to put the Scripted data source code when I deploy the report
> design to JBoss where I run the web application?
>
> I need to write the script using Java and references classes in the jars
> under WEB-INF of the web application. When and how does the script get
> compiled? Only JRE is installed on target machine.
>
> Thanks,
> Dave
Re: how to set data source connection string at runtime [message #631223 is a reply to message #630940] Wed, 06 October 2010 15:50 Go to previous messageGo to next message
Dave Missing name is currently offline Dave Missing nameFriend
Messages: 20
Registered: October 2010
Junior Member
Hi Jason,

Thanks!

I created a servlet to render a report design. but I could not make the created chart image show on the web page. The code for image setup:

HTMLRenderOption options = new HTMLRenderOption();

options.setOutputStream(os);
options.setOutputFormat("html");

String imageBaseURL = "/bi/images";
options.setBaseImageURL(imageBaseURL);
String imageDir = <a local dir>
options.setImageDirectory(imageDir);
options.setEmbeddable(true);

task.setRenderOption(options);
....
----------
On the server side, the chart image was created successfully.
Is there an example for rendering in HTML? I am using the latest BIRT 2.6.1.

I like to see the Viewer servlet source code. I checked the CVS source code, but could not find the servlet :

org.eclipse.birt.report.servlet.ViewerServlet

where can I find the source code?

Thanks
Dave
Re: how to set data source connection string at runtime [message #631290 is a reply to message #631223] Wed, 06 October 2010 19:50 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Dave
Is your os the response.getOutputStream object?

Un-comment the html lines and comment out the pdf ones. You can also
render to a file output and look at the image source tag to see what is
happening.

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

//get report name and launch the engine
//resp.setContentType("text/html");
resp.setContentType( "application/pdf" );
resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
String reportName = req.getParameter("ReportName");
ServletContext sc = req.getSession().getServletContext();
this.birtReportEngine = BirtEngine.getBirtEngine(sc);



IReportRunnable design;
try
{
//Open report design
design = birtReportEngine.openReportDesign(
sc.getRealPath("/Reports")+"/"+reportName );
//create task to run and render report
IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(
design );
//task.getAppContext().put("BIRT_VIEWER_HTTPSERVLET_REQUEST ", req );

//set output options
// HTMLRenderOption options = new HTMLRenderOption();
// options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML) ;
// options.setOutputStream(resp.getOutputStream());
// options.setImageHandler(new HTMLServerImageHandler());
// options.setBaseImageURL(req.getContextPath()+"/images");
// options.setImageDirectory(sc.getRealPath("/images"));


PDFRenderOption options = new PDFRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
//resp.setHeader( "Content-Disposition", "inline;
filename=\"test.pdf\"" );
options.setOutputStream(resp.getOutputStream());
task.setRenderOption(options);


//run report
task.run();
task.close();
}catch (Exception e){

e.printStackTrace();
throw new ServletException( e );
}
}

The viewer servlet code is in the org.eclipse.birt.report.viewer
project in the source tree.

Jason


On 10/6/2010 11:50 AM, Dave wrote:
> Hi Jason,
>
> Thanks!
> I created a servlet to render a report design. but I could not make the
> created chart image show on the web page. The code for image setup:
>
> HTMLRenderOption options = new HTMLRenderOption();
>
> options.setOutputStream(os);
> options.setOutputFormat("html");
>
> String imageBaseURL = "/bi/images";
> options.setBaseImageURL(imageBaseURL);
> String imageDir = <a local dir>
> options.setImageDirectory(imageDir);
> options.setEmbeddable(true);
> task.setRenderOption(options);
> ....
> ----------
> On the server side, the chart image was created successfully.
> Is there an example for rendering in HTML? I am using the latest BIRT
> 2.6.1.
>
> I like to see the Viewer servlet source code. I checked the CVS source
> code, but could not find the servlet :
>
> org.eclipse.birt.report.servlet.ViewerServlet
>
> where can I find the source code?
>
> Thanks
> Dave
Re: how to set data source connection string at runtime [message #631320 is a reply to message #631290] Thu, 07 October 2010 04:38 Go to previous messageGo to next message
Dave Missing name is currently offline Dave Missing nameFriend
Messages: 20
Registered: October 2010
Junior Member
Hi Jason,

It is solved. SVG format is not supported in my IE8 browser. After I changed chart format to png, it is working.

Thanks
Dave
Re: how to set data source connection string at runtime [message #631333 is a reply to message #630691] Thu, 07 October 2010 06:48 Go to previous messageGo to next message
Dave Missing name is currently offline Dave Missing nameFriend
Messages: 20
Registered: October 2010
Junior Member
Is there a way to define chart output format as a report parameter, or API to set chart output format?
Thanks,
Dave
Re: how to set data source connection string at runtime [message #631446 is a reply to message #631333] Thu, 07 October 2010 14:48 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Dave,

You can do this with the chart simple api. Take a look at this example.
http://www.birt-exchange.org/org/devshare/designing-birt-rep orts/1266-using-chart-simple-api-to-change-chart-output-form at/

Jason

On 10/7/2010 2:48 AM, Dave wrote:
> Is there a way to define chart output format as a report parameter, or
> API to set chart output format? Thanks,
> Dave
Re: how to set data source connection string at runtime [message #643107 is a reply to message #630691] Sat, 04 December 2010 14:40 Go to previous messageGo to next message
Shahab  is currently offline Shahab Friend
Messages: 4
Registered: December 2010
Junior Member
Can any one give me an example of connection url plz?
task.setParameter("myrunitmeconnectionurl",??????????);
i tried this but it didnt worked Sad
task.setParameterValue("myrunitmeconnectionurl","jdbc:oracle:thin:ccp/ccp@LOCALHOST:1521:CCPDB");

[Updated on: Sat, 04 December 2010 14:41]

Report message to a moderator

Re: how to set data source connection string at runtime [message #643407 is a reply to message #643107] Mon, 06 December 2010 18:48 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Is myruntimeconnectionurl a report parameter?
if it is you could do something like:

in beforeOpen of the datasource:

this.setExtensionProperty("odaURL",params["myruntimeconnectionurl "].value);

in your code

task.setParameter("myruntimeconnectionurl",""jdbc:mysql://localhost/mysql"");

Jason

On 12/4/2010 9:40 AM, Shahab wrote:
> Can any one give me an example of connection url plz?
> task.setParameter("myrunitmeconnectionurl",??????????);
Previous Topic:2.3.2 suppress records in data set
Next Topic:Runtime connection string problem
Goto Forum:
  


Current Time: Tue Apr 16 18:39:37 GMT 2024

Powered by FUDForum. Page generated in 0.91287 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top