• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

Simple SQL Applet

Hey all, I'm trying to write my first SQL applet which connects to an Access database.  I'm just trying to get the framework of this to work so I can experiement with it later.  

I am using an ODBC bridge driver.  
Here is my error:

java.security.AccessControlException: access denied (java.lang.RuntimePermissi
        at java.security.AccessControlContext.checkPermission(AccessControlCon
        at java.security.AccessController.checkPermission(AccessController.jav
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
        at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1
        at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:16

        at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:109)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:130)
        at SqlTest.init(SqlTest.java:39)
        at sun.applet.AppletPanel.run(AppletPanel.java:341)
        at java.lang.Thread.run(Thread.java:536)

Here is my Applet: VERY SIMPLE -- Dont laugh:

 * @(#)SqlTest.java 1.0 02/04/10
 * You can modify the template of this file in the
 * directory ..\JCreator\Templates\Template_2\Project_Name.java
 * You can also create your own project template by making a new
 * folder in the directory ..\JCreator\Template\. Use the other
 * templates as examples.

import java.awt.*;
import java.applet.*;
import java.sql.*;
import javax.swing.*;

public class SqlTest extends JApplet {
     String fName = new String();
     String lName = new String();
     public void init() {
          String url = "jdbc:odbc:dsnTest";
          String sqlString = "Select * Customer";
          ResultSet rs;
          Statement strSQL;
          Connection con;
               //create instance of the driver
               //creat the connection
               con = DriverManager.getConnection(url);
               //make sql statment
               strSQL = con.createStatement();
               rs = strSQL.executeQuery(sqlString);
                    fName = rs.getString("First Name");
                    lName = rs.getString("Last Name");
                    if(fName == null)
                    if(lName == null)
                         System.out.println("Last name is null");
          //catch all exceptions
          catch(Exception e)


     public void paint(Graphics g)
          g.drawString("First Name: " + fName, 50, 60);
  • 3
1 Solution
 The exception you are getting is thrown by the applet security manager and it does not have to do with errors in your code. Bare in mind that applets can only communicate with the database server that resides on the same machine where Applet was downloaded from. You cannot connect to any other server without first signing the Applet with a digital certificate.

  Hope it helps.
smartin7Author Commented:
   Thanks for the information, thats exactly what I need.  It appears I need to create a policy file.  This is a great link.  Thanks again!

 No problem. Thank you for the points :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now