pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Lew <noone@lewscanon.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: Thu, 03 Jun 2010 14:23:15 +0800
Message-ID: <4C074A53.9020004@postnewspapers.com.au> (raw)
In-Reply-To: <hu6nna$crj$1@news.albasani.net>
References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
	<4C05F409.7060805@postnewspapers.com.au>
	<hu6nna$crj$1@news.albasani.net>

On 3/06/2010 6:58 AM, Lew wrote:


>> You can use the classloader that loaded the currently running object
>> with:
>>
>> this.getClass().getClassLoader().loadClass('org.postgresql.Driver');
>
> The driver should be loaded in a static context, not an instance
> context. Furthermore, that code as shown will not compile.

Oops, wrong quotes. Point.

> Further
> furthermore, I see nothing in the documentation for
> 'ClassLoader#loadClass()' that promises to initialize the class, unlike
> 'Class.forName()'. If the class is not initialized, the driver won't
> register with the 'DriverManager'. I think you're selling a pig in a
> poke here.

Fair call - the beahaviour would depend on the classloader, and probably 
shouldn't be assumed.

> Go with the Tomcat way and forget the kludgey direct uses of Java
> reflection.

The fact that I haven't done much in servelet environments kinda shows, 
I suspect. JNDI is certainly the way to go based on what you referred to.

--
Craig Ringer



view thread (14+ messages)  latest in thread

Message-ID: <4C074A53.9020004@postnewspapers.com.au>
Permalink:  ../4C074A53.9020004@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4C074A53.9020004@postnewspapers.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@postnewspapers.com.au, noone@lewscanon.com
  Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
  In-Reply-To: <4C074A53.9020004@postnewspapers.com.au>
  References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> <4C05F409.7060805@postnewspapers.com.au> <hu6nna$crj$1@news.albasani.net> <4C074A53.9020004@postnewspapers.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox