Getting Around the Sandbox

Applets run in a JVM in your browser. For security reasons, applets, by default, run with restricted access to your computer’s local resources. This restricted access to your computer’s local resources, or " sandbox” as it is affectionately (sometimes not-so-affectionately) called, limits an applet’s ability to contact other computers over the network. The rule is that applets are limited to opening sockets , or network connections, only to the host from which they are downloaded. In effect, this limits any applet to connecting to a database only on the same host from which it was downloaded. If your database is installed on the same host as your web server, then this does not pose a problem, but often, databases reside on a host of their own. When the latter is the case, there are two ways you can work around this limitation using JDBC. The first is to use Oracle’s Connection Manager. The second is to get socket permissions for your applet.

If you try to connect to a database on a host other than the source of the applet, you’ll get a security exception. For example, the following is a security exception received from Internet Explorer while running the applet named TestApplet:

init(  ): loading OracleDriver for applet created at 2000-09-30 19:20:21.606
init(  ): getting connection
com.ms.security.SecurityExceptionEx[TestAppletInitDestroy.init]: cannot connect to 
"dssnt01"

Here is the same exception obtained from Netscape Navigator:

init( ): loading OracleDriver ...

Get Java Programming with Oracle JDBC now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.