-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stefan,

I'm no expert with Axis WebService, but I do have a question about your
use of the javax.sql.DataSource object:

Stefan Deitmer wrote:
> This is how I access the DataSource in the Axis WebService's LifeCycle
> object startup routine:
> 
>    public void startUp(ConfigurationContext configctx, AxisService
> service) {

...

>            service.addParameter(new Parameter(Constants.DATASOURCE, ds));

Is it customary to push a DataSource into the service's "parameters"?
Since the DataSource is always available via JNDI, why not simply grab
it from the JNDI context whenever you need it?

Going through JNDI has the added benefit of always getting you the right
object. If you were to reconfigure (or replace, really) the DataSource
in the JNDI context, your updates wouldn't be available to the web service.

>    SQLException while trying to get connection : Cannot load JDBC driver
> class 'org.postgresql.Driver'

I suspect you are just missing the PostgreSQL driver jar file. Can you
find it in any of the (hopefully) obvious places? I would start by
looking in /usr/share/tomcat5.5 and its subdirs.

> Replacing above code with the following works without errors:
> 
>        try
>        {
>            Class.forName("org.postgresql.Driver");
>            conn =
> DriverManager.getConnection("jdbc:postgresql://localhost/database",
> "user", "password");
>        }catch (Exception e) {
>            LOG.error("SQLException while trying to get connection: "
>                    + e.getMessage());
>        }

Sounds like the driver JAR file is packaged with your webapp (that is,
in yourapp/WEB-INF/lib/postgresql.jar). If you want to use Tomcat's
connection pooling (and you probably /do/), then you need to MOVE that
JAR file from your webapp's lib directory into Tomcat's libraries
directory. For Tomcat 5.5, you should probably put it into common/lib
under your Tomcat's real installation directory (maybe
/usr/share/tomcat5.5/common/lib).

> This is my first project with Tomcat, Axis, JDBC and PostgreSQL, and
> also the first time I'm seriously using Java in a very long time,
> so please have some patience with me if I'm missing something essential
> here.


You provided a perfect amount of information, actually. Thanks for
providing all the info you did!

> How comes Class.forName works when I call
> it directly, but not when the DataSource class calls it internally?

When using the DataSource, you are attempting to use Tomcat's connection
pool. Tomcat needs to be able to load the driver from a JAR file
/before/ consulting your webapp's libraries. When you use the
DriverManager, you are bypassing all that and loading the driver
"normally" through your webapp's classloader.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkk4UwYACgkQ9CaO5/Lv0PArlQCgkDShHM1KPolqhie10rXy5T7l
ulsAn1HGPq3TL1ElwW6lWsafU4eFD409
=1tU5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to