Birt creates a data source with script JavaScript and reads the database information from the configuration file __ Database

Source: Internet
Author: User
You can use script to solve the first problem.
You can define a parameter to specify the path to the properties file, and then create a datasource.
Edit the Beforeopen event in DataSource script, referring to the following code:

=======================================
Importpackage (Packages.java.io);
Importpackage (Packages.java.util);

Fin = new Java.io.FileInputStream (New String (params["Propfile"]));
props = new Java.util.Properties ();
Props.load (Fin);

Extensionproperties.odaurl = new String (props.getproperty ("url"));
Extensionproperties.odadriverclass = new String (Props.getproperty ("Driver"));
Extensionproperties.odauser = new String (Props.getproperty ("userid"));
Extensionproperties.odapassword = new String (Props.getproperty ("password"));

Fin.close ();

This allows you to dynamically read data source configuration information from the properties file.

--------------------------------------------------------------------------------------------------------------- -You can write the configuration file dead in the code, or you can define the report parameters, please note params["Propfile"] here.
The code here only supports absolute paths, which may not be appropriate in the case of deployment, and can be modified to support relative paths relative to the application root directory you publish.

Importpackage (packages.java.io,packages.java.util,packages.java.net);
Importpackage (Packages.javax.servlet.http);

req = Reportcontext.gethttpservletrequest ();
Proppath = new String (params["Propfile"]);
if (Proppath.charat (0)!= "/")
Proppath = "/" + Proppath;

url = req.getsession (). Getservletcontext (). getresource (Proppath);
if (URL!= null)
{
props = new Java.util.Properties ();
Props.load (Url.openstream ());

Extensionproperties.odaurl = new String (props.getproperty ("url"));
Extensionproperties.odadriverclass = new String (Props.getproperty ("Driver"));
Extensionproperties.odauser = new String (Props.getproperty ("userid"));
Extensionproperties.odapassword = new String (Props.getproperty ("password"));
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.