How to allow Java applet to use MySQL?

I recently got a hobby java project embedded in a page thanks to this site itself , but now I'm having some security issues.

I have include:

import java.sql.*;

and line:

Class.forName("com.mysql.jdbc.Driver").newInstance();

as well as the mysql.jar file in my src directory, it works from the console, and in the applet works fine from the applet to this forName () line in my code, where it throws an exception:

    Exception: com.mysql.jdbc.Driverjava.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.-1)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission (Unknown Source)
    at java.lang.SecurityManager.checkPermission (Unknown Source)
    at java.lang.SecurityManager.checkExit (Unknown Source)
    at java.lang.Runtime.exit (Unknown Source)
    at java.lang.System.exit (Unknown Source)
    at applet.Database.connectDB (Database.java:80)
    etc ...

I think I can fix it using the client.policy file, otherwise I may need to write an abstraction layer that uses the network connection of the server and client to the request from the server side ...

I am sure that the Java gurus here probably know this best.

+3
source share
6 answers

, System.exit() Class.forName(). , System.exit() , JVM. , 80 Class.forName(), 80 - , System.exit(), ?

, jar mysql , ARCHIVE, :

<APPLET ARCHIVE="mysql.jar" CODEBASE="./src/" ...

, mysql IP/hostname, -, , . , , . - , , XML - , . , , , , , , , mysql , .

+2

JDBC , , , .

+2

- HTTP- , , . JSON XML - ( , AJAX, XML JSON ).

+1

(@Leigh Caldwell), . MySQL, . , . , / MySQL , IP. , .

(XMLRPC ). , HSQLDB . - . XMLRPC.

+1

newInstance(). , Class.forName() .

0

An exception indicates that the applet could not load the driver class. Your applet needs to download the jar containing the class at runtime via HTTP, so you must have the jar (mysql.jar or something else called) available on the web server.

Once you solve this problem, the user will need to allow applet permissions so that he can connect the TCP socket to the mysql db server. They will be called using the dialog box ...

0
source

Source: https://habr.com/ru/post/1698382/


All Articles