Birt uses the script JavaScript to create a data source and read the database information from the configuration file.

Source: Internet
Author: User
You can use scripts to solve the first problem.
You can define a parameter to specify the path of the properties file and then create a datasource.
Edit the beforeopen event in the datasource script. refer 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 ();

In this way, the data source configuration information can be dynamically read from the properties file.

Bytes ----------------------------------------------------------------------------------------------------------------

You can write the configuration file in the code or define it as a report parameter. Note the following: Params ["propfile.
The code here only supports absolute paths, which may not be applicable in deployment. You can modify the supported relative paths relative to the application root directory you published.

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.