wood burning stoves 2.0*
The moose likes Applets and the fly likes java.security. Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "java.security. Error" Watch "java.security. Error" New topic

java.security. Error

Rakesh Chaudhary
Ranch Hand

Joined: Feb 19, 2008
Posts: 120
Hiii Sheriff...I am getting a Exception of some kind of Access Control when run the following code ....I know it is something to read with the Policy...fundas...I tried reading and solving the problem but its not clicking.....I have a Excel Sheet by the name....Lib from which I am trying to read the values on my applet....thanks in advance

/*<applet code="Example.class" width=300 height=300>
</applet> */

import java.applet.Applet;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.security.*;

public class Example extends Applet
public void init()
Connection con = null;
con = DriverManager.getConnection( "jdbc dbc:Lib", "", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select Books, Aut, No from [lib$]");
while (rs.next())


catch(Exception e)

System.out.println("Error in init\n"+e);

// perform the security-sensitive operation


// return null;

the following are the error messages I am getting on the console

Error in init

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1512)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:190)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:116)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at Example.init(Example.java:18)
at sun.applet.AppletPanel.run(AppletPanel.java:374)

Acquire the unexpected.......
Preparing for SCJP 6
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41101
Yes, you can't use local resources like ODBC in an unsigned applet due to security restrictions. The two principal ways around this are explained in HowCanAnAppletReadFilesOnTheLocalFileSystem

In the future, please UseCodeTags when posting code of any length. It is unnecessarily hard to read as it is.
[ May 05, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Rakesh Chaudhary
Ranch Hand

Joined: Feb 19, 2008
Posts: 120
Thanks Ulf... I searched ranch for the same...and got exactly the same Answer
I am sorry Mate ...but I am running short of time....the link has a number of pages for the security features but No Code Snippnets to Explain....

Imfact there are Code Snippnets like

Can you Please Tell me the Code Snippnet which I should put in my code to get it pass the Security..policy Barrier....
Aka TO SIGN an Applet ....Thanks
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41101
What you quoted is not code, it is an excerpt of a security policy. As such it's not used for applet signing (which the first half of the FAQ page is about), but for altering the local security policy (which the second half talks about). You can't embed that snippet in the applet code; it needs to be installed on each client machine where the applet should run.

The link in the "Here is an example of that." sentence is probably the shortest possible introduction to that you can find.
Rakesh Chaudhary
Ranch Hand

Joined: Feb 19, 2008
Posts: 120
Thanks Ulf....I got it now.....

But I am Worried again that I must implement my neurons before posting like morons.....Anywaysss.....See you if am Stuck ...again....

I have Signed the Applet now and its working....
It is sorta covered in the JavaRanch Style Guide.
subject: java.security. Error
Similar Threads
Display Problem in JTable
JTDS jdbc driver
JNDI in Servlets
Populating Combo Box using one of the fields in oracle
Oracle Connectivity Error