简体   繁体   中英

java.security.AccessControlException in applet communicating with mysql

My school's programming club is starting a tutoring program, and I have built a Java applet that students can use to request sessions. The applet communicates with a database that has a table that stores the availability of the tutors, and shows the user the available times.

First off: I know it's a bad idea to have an applet communicate directly with a database, for security reasons. That being said, this is a fairly low-risk situation (nothing "sensitive" is stored on the database), and this solution is only temporary (we don't currently have a server capable of running tomcat, so everything needs to be done client-side).

The applet GUI loads correctly, but throws a java.security.AccessControlException ("java.lang.RuntimePermission" "setContextClassLoader") exception when it initializes the class that tries to access the database, and no data is loaded. How can I solve this problem?

EDIT: I've changed my code so that the DB communications occur on the same thread as the GUI. Now I'm getting this exception:

Exception in thread "Thread-46" java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.StringUtils
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:298)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at helpsessions.DBHandler.run(DBHandler.java:53)
at java.lang.Thread.run(Unknown Source)

Applets have a very restricted security model by default, in order to extend the facilities available to the applet you will need to sign the applet, and then write an updated security policy with the extended permissions you require.

Your second problem - class not found - is because the driver is not being distributed with the applet.

I found this with reference to Java 1.1.

If you're using an applet, then you must place those JARs and class files in the applet's codebase directory and/or archive locations

I'm not sure how relevant is to the latest versions of Java, but I would suggest that is your best option to make the driver Jar available to the applet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM