Applets and mysql

software development

#1

Hey I’m kinda new to mysql and applets.

I’m trying to make a simple applet for reading/writing to a mysql database but it just won’t connect. I do the same thing from a normal java application and it works allright.

DriverManager.getConnection(“jdbc:mysql://mysql.madhamster.net/pastebin?”+
“user=user&password=password”);

(fictional user and pword :wink: )

gives the exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission mysql.madhamster.net resolve)

Is the problem the adress? and can anyone point out what the adress have to be inorder to connect to the database?
Is the problem one of those limitations in applets?

cheers
Stian


#2

Is this Java thing running from on the DreamHost server, on a remote server that you control, or inside a user’s browser?

If it’s running from on a DreamHost server, then there’s probably not much I can do except tell you to make sure that your syntax is right and that you’re using the right username and password. Someone with a bit of Java applet experience could probably do better, but that someone is not me :wink:

If it’s running on a separate server that you control, then the reason for the access denied error might be that your server is not in the list of servers which MySQL will accept connections from. By default, for security reasons, DreamHost only allows connections to MySQL from DreamHost servers. You can add your own server by going to your web control panel under Manage -> MySQL, clicking the name of your MySQL user, and adding your server to the “Allowable Hosts” section.

If this is running inside a user’s browser, then I strongly suggest you find a different method. To begin with, you’ll have the exact same problem as using your own server with regard to where connections are being allowed from, but you won’t have the single easily identifiable server to add as an allowable host. While it is possible to open access to everyone, that comes with major security risks. Even more importantly, it is a very bad idea to make your password accessible from the user’s browser. Passwords of that sort should always be kept server-side in an environment you control.


#3

Hey thank you for the response.

The problem was what I suspected, one of these “security” limitations in applets, the sandbox thing. The applet was on my dreamhost webspace, trying to connect to a mysql database on dreamhost and I had added my ip to the list of allowed ip’s on the database.

As I said it worked just fine with a normal java application but not with the applet.

Applets have all sorts of limitations to them, you can only read files on the webhost server, not get information from the client computers registry and apparantly not use databases(the last part is really annoying when the database is even on the same webhost).

I solved the problem though just made a htmlform that posts data to a php script, then the script stores and get data from the database and pass it along to the applet.

Another solution would ofc be to make a servlet instead :slight_smile:

cheers,
Stian Farstad