struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jimmy Emmanual <jim...@imsi.com>
Subject RE: struts 1.1:Multiple DataSources
Date Thu, 20 Mar 2003 13:56:33 GMT
John, read the posts on Connection Pool. I've got it working in 1.0.2 by
setting the "key" as an Attribute of the <datasource> tag not as a property.

struts-config file:

   <data-source key="one" >
     ...
     ... 
   </data-source> 

   <data-source>

     <set-property property="key" value="two" />
     ...
     ...	

   </data-source> 

Now in the Action Class:

ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)context.getAttribute("one");

OR you can cast it as a GenericDataSource to print out its properites:

ServletContext context = servlet.getServletContext();
org.apache.struts.util.GenericDataSource genSource = 
 
(org.apache.struts.util.GenericDataSource)context.getAttribute("one");
	  	
System.out.println(genSource.getDescription());
System.out.println(genSource.getDriverClass());
System.out.println(genSource.getUrl());

This works for Struts 1.0.2. Not sure if it will work with any other
version.

Thanks to Dennis Lee and David Graham!!

-----Original Message-----
From: John Wilson [mailto:john.wilson@intronet.com]
Sent: March 20, 2003 3:54 AM
To: 'struts-user@jakarta.apache.org'
Subject: struts 1.1:Multiple DataSources 


Using struts 1.1 with SQL2000 Database.

Defined two data sources in my strust-conf.xml:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 <data-sources>

   <data-source>

     <set-property property="key" value="one" />
     ...
     ... 
   </data-source> 

   <data-source>

     <set-property property="key" value="two" />
     ...
     ...	

   </data-source> 

</data-sources>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


>From with in my action classes 

  dataSource = getDataSource(request,"one"); 
   or/
  dataSource = getDataSource(request,"two"); 

both of these throw a null pointer exception.

However  both work fine with getDataSource(request) when I define only one
datasource and don't pass in the key.

Does anyone have a solution or a reference web site?


thanks in Advance

John


 









---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message