On Thu, 9 Aug 2001, Jeffrey Bird wrote:
> I am new to struts and am having a bit of trouble getting multiple
> datasources working. I have two datasources defined in my
> struts-config.xml. The documentation is unclear on how to define an
> identifier for each datasource.
>
> The other problem is how to reference the datasource in my action class.
> What do I have to supply as the parameter to the
> servlet.findDataSource() method? I am currently using null, which
> returns the first datasource that I have defined. I want to be able to
> reference the other.
>
> Further to this, does anybody have a concrete example of using the
> DBTags taglib with a struts defined datasource. Again, the documentation
> is very sparse on this subject.
>
The basic principle is that every data source you define is made available
to your application's Actions as a servlet context attribute. The first
data source receives a default name (so you can just call
servlet.getDataSource() with no argument from an Action). Beyond that,
you have to assign specific names to the data sources, like this:
and then you can reference that particular data source from an Action:
DataSource ds = servlet.getDataSource("myname");
or from a JSP page as an application-scope bean named "myname". The
latter is how you would access it from DBTags.
> Thanks
> Jeff Bird
>
Craig