Reputation: 41
So I wrote a JApplet that connects to and does some stuff with a MySQL server. When I test it in Eclipse it works just fine. I have the IP address, the database name, the username I'm using (root) and the password hardcoded into the program at the moment. If I have the IP as localhost, or 127.0.0.1 (same thing but yeah), or 192.168.x.x (my PC's local address) the JApplet while being run from Eclipse will connect to the MySQL server with no issues. Also, if I open another terminal and login to mysql that way it also works.
However, if I jar the project using Eclipse, include the mysql driver in the HTML applet tag and run it through a web browser on the same machine it does not work.
Here is the HTML tag that I am using:
<applet code="mysqlApp.MysqlInterface.class"
archive="LoginDemo.jar, mysql-connector-java-5.1.18-bin.jar"
height="150" width="450">
Your browser does not support the <code>applet</code> tag.
</applet>
I have tried it in Firefox 10.* with port 3306 forwarded on my router and my software firewall turned off. Also, the MySQL server is bound to 0.0.0.0 (it accepts connection attempts on all interfaces) and TCP/IP is enabled (skip-networking option is not used). I get a message dialog window saying that no sql connection can be made (what I programmed it to do) and I get the following exception in the Java console:
SQLException: 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.
SQLState: 08S01
VendorError: 0
I also tried it in the latest version of Internet Explorer for Windows 7 x64 and when I click on the buttons that are supposed to connect it to the server the webpage freezes.
Nothing prints out to the console where mysqld is running (I ran it with an admin terminal using mysqld --console)
Does anybody have any ideas? I have been looking for a solution for days but everything I find that seems like it may work has one or two little details that makes it not applicable to my issue.
Yes, I know that I should not be having the applet communicate directly with the database if this is to be used in production code (major security issue) but I am in the early stages of doing this and am trying to figure this out for testing purposes.
Thanks.
Upvotes: 0
Views: 360
Reputation: 11
You should have your applet communicate to some backend (java or php) through ajax. Then use the backend to communicate with mysql. A good place for ajax is http://prototypejs.org/assets/2010/10/12/prototype.js.
Upvotes: 1