# Probleme mit Applet mit SQL im Browser



## cyberjosi (22. Apr 2010)

Hallo!

Ich bin noch ziemlich neu im Bereich Java Applets aber nun habe ich mein Applet vollendet.
Jedoch stellt sich mir ein großes Problem in den Weg. 

Ich habe ein Applet programmiert das von einer Datenbank einliest. Alles kein Problem mit Netbeans, jedoch wenn ich das Applet im Browser starten will erhalte ich folgende Fehlermeldung.


```
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2260)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:787)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:357)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at quizadmin.DatabaseManagement.connect(DatabaseManagement.java:34)
	at quizadmin.DatabaseManagement.login(DatabaseManagement.java:71)
	at quizadmin.QuizAdminGUI.onLogin(QuizAdminGUI.java:208)
	at quizadmin.QuizAdminGUI.access$100(QuizAdminGUI.java:20)
	at quizadmin.QuizAdminGUI$2.actionPerformed(QuizAdminGUI.java:83)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2181)
	... 40 more
Caused by: java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 83.169.22.16:3306 connect,resolve)
	at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:293)
	... 41 more
java.lang.NullPointerException
	at quizadmin.DatabaseManagement.login(DatabaseManagement.java:72)
	at quizadmin.QuizAdminGUI.onLogin(QuizAdminGUI.java:208)
	at quizadmin.QuizAdminGUI.access$100(QuizAdminGUI.java:20)
	at quizadmin.QuizAdminGUI$2.actionPerformed(QuizAdminGUI.java:83)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Error Trace in getConnection() : null
```

Nach endlos langer Suche im Internet versuchte ich mein Applet zu signieren.
Das signieren ging schnell jedoch bekomm ich das Applet im Browser nicht mal zu gesicht.


```
java.lang.SecurityException: trusted loader attempted to load sandboxed resource from file:/C:/Users/J%C3%B6shke/Desktop/QuizAdmin/build/new/tst.jar
	at com.sun.deploy.security.CPCallbackHandler$ParentCallback.check(Unknown Source)
	at com.sun.deploy.security.CPCallbackHandler$ParentCallback.access$1400(Unknown Source)
	at com.sun.deploy.security.CPCallbackHandler$ChildElement.checkResource(Unknown Source)
	at com.sun.deploy.security.DeployURLClassPath$JarLoader.checkResource(Unknown Source)
	at com.sun.deploy.security.DeployURLClassPath$JarLoader.getResource(Unknown Source)
	at com.sun.deploy.security.DeployURLClassPath.getResource(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Ausnahme: java.lang.SecurityException: trusted loader attempted to load sandboxed resource from file:/C:/Users/J%C3%B6shke/Desktop/QuizAdmin/build/new/tst.jar
```

Hoffe jemand kann mir helfen!
Am besten wäre eine genaue Beschreibung zur Lösung des Problem wäre sehr Dankbar.

Mfg cyberjosi


----------



## L-ectron-X (22. Apr 2010)

Zu allererst: Man sollte mit Applets nie direkt auf Datenbanken zugreifen, erst recht nicht, wenn beide Teile im Internet liegen.
Deine Anwendung könnte in weniger als 2 Minuten gehackt werden...

Aus den Fehlermeldungen erschließt sich mir leider kein Zusammenhang mit einem möglichen Fehler.
Was ist tst.jar? Von wem wird es geladen/benutzt? Wie hast du dein Applet eingebunden? Ich könnte noch weitere Fragen stellen, aber angesichts des Kontextes macht das keinen Sinn.


----------



## cyberjosi (22. Apr 2010)

Also die tst.jar wäre die signierte QuizAdmin Jar Datei 

Hier wäre der Code mit dem ich beide Jar Dateien einbinde:

```
<HTML>
<applet code="quizadmin/QuizAdminGUI.class" archive="QuizAdmin.jar" width="500" height="500">
</applet>
</HTML>
```
Also wegen der Sicherheit ist es kein Problem da das Applet nie für die Öffentlichkeit online gehen wird.

Weitere Infos zum Problem:
Die com.mysql.jdbc.exceptions.jdbc4.CommunicationsException tritten nur dann auf wenn eine Verbindung zur Datenbank aufgebaut wird. 

Die java.lang.SecurityException tritten sofort nach dem Laden des Applets auf!

Glaube aber nicht das es mit dem Code ein Problem gibt da es im Netbeans einwandfrei läuft.

Falls Ihr noch mehr Fragen habt zu meinen Problem postet bitte sie.

Mfg cyberjosi


----------



## L-ectron-X (23. Apr 2010)

OK, das passt so.
Hast du den DB-Treiber auch signiert? Wenn nicht, könnte das die Ursache deines Problems sein.


----------



## cyberjosi (23. Apr 2010)

Danke! Das ware die Lösung zu meinem Problem! :toll:


----------

