Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Lew <noone(at)lewscanon(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: 2010-06-03 06:23:15
Message-ID: 4C074A53.9020004@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Guy Rouillier 2010-06-03 23:51:17 Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Previous Message Craig Ringer 2010-06-03 06:19:19 Re: JDBC SSL with postgresql