Re: Newbie question - Applet works only in appletviewer

From: Sam Varshavchik <mrsam(at)courier-mta(dot)com>
To: "Shmuel A(dot) Kahn" <Shmuel(at)Kam-motion(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Newbie question - Applet works only in appletviewer
Date: 2002-06-05 20:29:39
Message-ID: courier.3CFE74B3.00004C20@ny.email-scan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Shmuel A. Kahn writes:

>> I am trying to write an applet for the internet, to display (output
>> only) some DB data. I managed to get my code to work as an application,
>> and even run under the appletviewer, but it fails under both Internet
>> Exploder 6. and Netscape 7.
>
> Woops!!
> Forget to mention I am crashing on the following exceptions:
>
> ---------------------------------------------------
> Error -- java.lang.ClassNotFoundException: org.postgresql.Driver
> Error -- java.sql.SQLException: No suitable driver
> Error -- java.lang.NullPointerException

Your browser's Java VM obviously does not have the PostgreSQL JDBC driver,
jdbc*.jar, installed. Hence when the browser downloads your applet, and
runs it, the PostgreSQL JDBC driver is not available.

appletviewer reads your CLASSPATH, and pulls in the JDBC driver that way,
but this mechanism is obviously not available in a real browser.

There are several possible ways to fix this. One is to insert jdbc*.jar
into your own applet's jar, so the browser ends up downloading both your
applet, and the JDBC driver. Besides being a rather hefty download, this is
not going to work anyway unless the PostgreSQL database is on the same
server as your applet. The browser's security manager will prevent the
application from logging in to any database not on the same server the
applet was loaded from.

A more common approach is to wrap all the database access code into a
separate class that's left on the server, and invoked via RMI. This'll work
rather well, provided that the known issues with Sun's rmiregistry are
squared away, and sending data over the network in cleartext isn't an issue.

--
Sam

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nick Fankhauser 2002-06-05 20:38:23 Re: Java GUI development
Previous Message Bear Giles 2002-06-05 20:21:39 Re: Java GUI development