0

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.

3
  • Is the applet digitally signed? Are any exceptions caught in the code and ignored? BTW - an applet should not have direct access to the DB. Commented Mar 3, 2012 at 22:22
  • No the Applet is not digitally signed, however I was having java.security issues with reading permissions and I edited the local java.policy file to where that issue went away. I tried to figure out how to sign it to fix that issue and while I found the jarsigner application I couldn't figure out how to create a keystore, etc. to use with it. No, I don't think I ignored any exceptions. Yeah, I know the applet should be communicating with PHP or something else, I'm just in the initial stages of testing this at the moment though. Thanks Commented Mar 3, 2012 at 23:33
  • Well, I forwarded port 3306 on my router, turned my software firewall off and digitally signed three different jars of the program (each one having a different IP for the mysql server hardcoded in: 127.0.0.1, 192.168.x.x and an external IP). I tried each one of the signed jars and I still cannot connect the the mysql server running on localhost, although I can through Eclipse. I don't understand what the issue is. Commented Mar 4, 2012 at 22:18

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I know that is what I should do (having the MySQL server open to the whole Internet is a security issue) but since I am in the early stages of this I am trying to get this to work for testing purposes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.