This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes java.policy setting not reflecting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.policy setting not reflecting" Watch "java.policy setting not reflecting" New topic

java.policy setting not reflecting

Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
I am writing an web based application using applets nadn eed to contact a MYSql database.

I am getting Access Denied exception.

In my java.policy file I added the following two lines :

permission "", "accept,connect,listen,resolve";

permission "localhost:3306", "accept,connect,listen,resolve";

There is an extra permission line Iin addition to the PropertyPermissions) :
permission "localhost:1024-", "listen";
that was already there on the server.

I am still getting the following exception : Any help will be greatly appreciated since I have a demo tomorrow. (Is there anyway to confugure the java.policy or file to allow the jar that contains my applet(dvt.jar) to access the underlying database.)


Unable to connect to any hosts due to exception: access denied ( connect,resolve)** BEGIN NESTED EXCEPTION ** access denied ( connect,resolve) access denied ( connect,resolve)at Source)at Source)at java.lang.SecurityManager.checkPermission(Unknown Source)at java.lang.SecurityManager.checkConnect(Unknown Source)at Source)at Source)at<init>(Unknown Source)at<init>(Unknown Source)at com.mysql.jdbc.StandardSocketFactory.connect( com.mysql.jdbc.MysqlIO.<init>( com.mysql.jdbc.Connection.createNewIO( com.mysql.jdbc.Connection.<init>( com.mysql.jdbc.NonRegisteringDriver.connect( java.sql.DriverManager.getConnection(Unknown Source)at java.sql.DriverManager.getConnection(Unknown Source)at vdt.VdtModuleApplet.getConnection( vdt.VdtModuleApplet.init( Source)at Source)** END NESTED EXCEPTION ** System = Inited, gotParameters, init propertiesGetting Connection
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Is there some place I need to specify explicitly where to find this java.policy file.
Platform is UNIX.

Joe Ess

Joined: Oct 29, 2001
Posts: 8836

It's probably too late to mention, but using an applet to directly contact a database is a Bad Idea. First, you have to give the applet a password and user name to contact the db which compromises security. Next, applets can't contact any server other than the one they are downloaded from (as you have discovered). You can get around this restriction by digitally signing the applet. I don't think just changing the policy file would do it, but I've never tried it.
Another work-around is to use your web server to host a service which the applet uses as a proxy to access other network resources, as described in the java tutorial
BTW, you are changing the policy file on the client, right?

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
I have changed the policy file to give "connect,listen,resolve,accept" for ""

It has not made any difference to the error.

I will try adding the digital signature to the applet.

I agree. Here's the link:
subject: java.policy setting not reflecting
Similar Threads
new to servlet
rmi policy file
why security manager doesn't work?
RMI example code fails
MYSql Driver ClassNotFound Exception