If I run this code: http://www.danny92.pastebin.com/m1f84b972
You will see that my Database connection connects then disconnects after actionPerformed.... why? :(
If I run this code: http://www.danny92.pastebin.com/m1f84b972
You will see that my Database connection connects then disconnects after actionPerformed.... why? :(
Applets have many resctrictions including network restrictions. Don't forget that applets run from the client side and not server side, therefore as a policy, applet was restricted to access company internal networks (the private networks)...
In short, your code is trying to access your database server (as it never connects because of the network restrictions placed on applets). It's trying to call a private network from a client side. Javascript follows the same restriction as it must never access a private network from client side.
More info here (http://www.wutka.com/hackingjava/ch3.htm)
I wouldn't recommend that an applet connect directly to a database. This exposes the database directly on the network - not a good practice.
A better idea might be to put a servlet in between the applet and the database. This will have several beneficial effects:
Line 39 has this code:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jgame", props);
Thus you only assign the Connection to a local variable, not the con
member variable in your applet.
Replace it with
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jgame", props);