Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » How to Connect to dynamic datasource using jdbc datasource
How to Connect to dynamic datasource using jdbc datasource [message #727359] Wed, 21 September 2011 04:52 Go to next message
cbr125x  is currently offline cbr125x Friend
Messages: 34
Registered: July 2011
Member
Hi All,
can somebody help me?
how to connect to dynamic database in BIRT using JDBC connection?
i found that in scripted datasource example, the example using class as the datasource but i want the jdbc datasource but it's dynamic.

i will explain the condition :
let's say i have a parameter named "DBPARAM".

in the beforeOpen events in datasource we put script :
if DBPARAM = "beta" then
The datasource connect to "serverBeta"
else
The datasource connect to "serverAlpha"

can we do this programmatically or must be in designer or how should i do to accomplish that condition?
Re: How to Connect to dynamic datasource using jdbc datasource [message #727651 is a reply to message #727359] Wed, 21 September 2011 18:38 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You could always set the oda url like:

if( params["DBPARAM"].value == "beta"){
this.setExtensionProperty("odaURL","jdbc:mysql://localhost/mysql");
}else{
..
..
}

if the beforeOpen script of the data source. You could also use
connection profile and have one for alpha and one for beta.


Jason


On 9/21/2011 12:52 AM, cbr125x wrote:
> Hi All, can somebody help me?
> how to connect to dynamic database in BIRT using JDBC connection?
> i found that in scripted datasource example, the example using class as
> the datasource but i want the jdbc datasource but it's dynamic.
>
> i will explain the condition :
> let's say i have a parameter named "DBPARAM".
>
> in the beforeOpen events in datasource we put script :
> if DBPARAM = "beta" then The datasource connect to "serverBeta"
> else
> The datasource connect to "serverAlpha"
>
> can we do this programmatically or must be in designer or how should i
> do to accomplish that condition?
>
Re: How to Connect to dynamic datasource using jdbc datasource [message #727876 is a reply to message #727651] Thu, 22 September 2011 06:31 Go to previous messageGo to next message
cbr125x  is currently offline cbr125x Friend
Messages: 34
Registered: July 2011
Member
Thx Jason

is this true, if i use sqlserver :
if( params["DBPARAM"].value == "beta"){
this.setExtensionProperty("odaURL","jdbc:sqlserver://server1/northwind;");
}else{
..
..
}

and also how can i get information for the property like "odaURL" in the setExtensionProperty?
i mean i don't know if the parameter for the "password", "username", etc.


Jason Weathersby wrote on Wed, 21 September 2011 14:38
You could always set the oda url like:

if( params["DBPARAM"].value == "beta"){
this.setExtensionProperty("odaURL","jdbc:mysql://localhost/mysql");
}else{
..
..
}

if the beforeOpen script of the data source. You could also use
connection profile and have one for alpha and one for beta.


Jason


On 9/21/2011 12:52 AM, cbr125x wrote:
> Hi All, can somebody help me?
> how to connect to dynamic database in BIRT using JDBC connection?
> i found that in scripted datasource example, the example using class as
> the datasource but i want the jdbc datasource but it's dynamic.
>
> i will explain the condition :
> let's say i have a parameter named "DBPARAM".
>
> in the beforeOpen events in datasource we put script :
> if DBPARAM = "beta" then The datasource connect to "serverBeta"
> else
> The datasource connect to "serverAlpha"
>
> can we do this programmatically or must be in designer or how should i
> do to accomplish that condition?
>

Re: How to Connect to dynamic datasource using jdbc datasource [message #728159 is a reply to message #727876] Thu, 22 September 2011 15:58 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

That should work. Take a look at the xml view to see the property names:

<property
name="odaDriverClass">com.mysql.jdbc.Driver</property>
<property name="odaURL">jdbc:mysql://localhost/mydb</property>
<property name="odaUser">root</property>
<encrypted-property name="odaPassword"
encryptionID="base64">cm9vdA==</encrypted-property>
<property name="odaJndiName">jdbc/MyDataSource</property>


ie odaUser..

Jason

On 9/22/2011 2:31 AM, cbr125x wrote:
> Thx Jason
>
> is this true, if i use sqlserver : if( params["DBPARAM"].value == "beta"){
> this.setExtensionProperty("odaURL","jdbc:sqlserver://server1/northwind;");
> }else{
> ..
> ..
> }
>
> and also how can i get information for the property like "odaURL" in the
> setExtensionProperty? i mean i don't know if the parameter for the
> "password", "username", etc.
>
>
> Jason Weathersby wrote on Wed, 21 September 2011 14:38
>> You could always set the oda url like:
>>
>> if( params["DBPARAM"].value == "beta"){
>> this.setExtensionProperty("odaURL","jdbc:mysql://localhost/mysql");
>> }else{
>> ..
>> ..
>> }
>>
>> if the beforeOpen script of the data source. You could also use
>> connection profile and have one for alpha and one for beta.
>>
>>
>> Jason
>>
>>
>> On 9/21/2011 12:52 AM, cbr125x wrote:
>> > Hi All, can somebody help me?
>> > how to connect to dynamic database in BIRT using JDBC connection?
>> > i found that in scripted datasource example, the example using class as
>> > the datasource but i want the jdbc datasource but it's dynamic.
>> >
>> > i will explain the condition :
>> > let's say i have a parameter named "DBPARAM".
>> >
>> > in the beforeOpen events in datasource we put script :
>> > if DBPARAM = "beta" then The datasource connect to "serverBeta"
>> > else
>> > The datasource connect to "serverAlpha"
>> >
>> > can we do this programmatically or must be in designer or how should i
>> > do to accomplish that condition?
>> >
>
>
Re: How to Connect to dynamic datasource using jdbc datasource [message #945666 is a reply to message #727359] Mon, 15 October 2012 14:11 Go to previous messageGo to next message
Saurabh Puri is currently offline Saurabh PuriFriend
Messages: 10
Registered: February 2012
Junior Member
Hi ,

I am trying to pass the database name from the jsp page as a report parameter to whom the report should connect.

I am using:

var db_name = params["db_name"].value;
url = "jdbc:mysql://localhost:3306/" + db_name;
this.setExtensionProperty("odaURL",url);


in the beforeOpen of datasources.

But then it is not taking the parameter value but is using the default value as specified.

Is there some way out??

Thanks in advance
Re: How to Connect to dynamic datasource using jdbc datasource [message #947378 is a reply to message #945666] Wed, 17 October 2012 03:27 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Can you add the following:
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/temp/dsevents.txt", true ) );
out.println( "oda url " + url);
out.close();
right before setting the extension property? Open the file that is created and verify that the url is correct.

Jason
Previous Topic:Replace total.count() aggration method
Next Topic:Eclipse debug perspective issue with required report parameters
Goto Forum:
  


Current Time: Thu Mar 28 14:46:34 GMT 2024

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

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

Back to the top