Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From: Christopher Elkins <chrise(at)scardini(dot)com>
To: GB Clark <postgres(at)vsservices(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --
Date: 2003-02-12 19:00:03
Message-ID: 3157863E-3EBC-11D7-A1D6-0003936808BE@scardini.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

This is off-topic, but it's not exactly well-documented anywhere.

On Tuesday, February 11, 2003, at 07:12 PM, GB Clark wrote:

> I had to include my database parameters INSIDE the context for my
> application. Can anyone tell
> me why this fixed my problem? Or is that where the database
> parameters should be anyway...

Typically, that's where they're defined. However, as you've noticed,
this is less than ideal for resources that you want to share across
webapp contexts.

> If I wanted another servlet to use the same datasource would I have to
> duplicate the parameters
> everytime?

You can configure global resources (i.e., in the
<GlobalNamingResources> section), but you need to use a slightly
different syntax in your webapp context in order for it to "see" them.

Specifically, add the relevant <Resource> and <ResourceParams> elements
to the global resources section. Then, in your webapp context add a
<ResourceLink> element.

For example,

<GlobalNamingResources>
<Resource name="jdbc/ globaldb" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/ globaldb">
.. the usual DBCP configuration stuff ...
</ResourceParams>
</GlobalNamingResources>
...
<Context path="/myapp">
<ResourceLink name="jdbc/mydb" global="jdbc/globaldb"
type="javax.sql.DataSource" />
</Context>

Your code can now lookup "java:comp/env/jdbc/mydb" and get a reference
to the globally-defined data source. Keep in mind that because this is
a Tomcat-specific configuration feature, you cannot define it in the
webapp's deployment descriptor (i.e., web.xml) and must therefore
deploy your webapp "manually" (e.g., through Tomcat's manager
application).

--
Christopher Elkins

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Daniel Serodio 2003-02-12 20:31:31 Re: getTableName
Previous Message Barry Lind 2003-02-12 17:54:12 Re: [HACKERS] Wrong charset mappings