Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Is this a java issue? JApplet with MySQL access.. can't connect to mySQL

    When I installed mysql on my Windows 7 machine I believe I chose some option about "only allow loopback connections", "disable TCP/IP" or something like that. The reason for this was because I wrote a Java application that uses JDBC to connect to the server and input some information.
    I have the address of the server hardcoded into the program (localhost@3306 or something like that) and my program connects and successfully inserts data when I start it from Eclipse.

    However, if I start the Applet with Java Web Start (double clicking a .jnlp file on my desktop) or embed the applet in a test HTML page I cannot connect to mysql. I assume this is because it goes through the web browser and mysql refuses TCP/IP (I think), or because it is being run through java I need the local address (192.168.x.x) or the outside IP (xxx.xxx.xxx.xxx) to connect.

    I'll probably change the program so there are options where you can change the IP of the database to connect to, but for right now I just want to figure this out.

    Is what I am saying about the program being loaded in Firefox as an applet, or through Java Web Start possible (that it now needs a 192.168.x.x or xxx.xxx.xxx.xxx address)? That doesn't seem right, but all I know is the localhost@3306 does not work unless I start it from within Eclipse.

    Thanks.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Is this a java issue? JApplet with MySQL access.. can't connect to mySQL

    Post the exception. This will give you the best explanation to the problem.

  3. #3
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: Is this a java issue? JApplet with MySQL access.. can't connect to mySQL

    Ok, well the first exception that I got was:
    "SQLException: No suitable driver found for jdbc:mysql://localhost:3306/inventory_users"
    So, I looked, and Eclipse did not export the JDBC driver with the rest of my stuff into the jar for some reason (still won't).
    So, in the HTML:
    <applet code="demoApp.DemoWindow.class"
    archive="LoginDemo.jar"
    height="150" width="450">
    Your browser does not support the <code>applet</code> tag.
    </applet>

    I changed to this:
    <applet code="demoApp.DemoWindow.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>

    and that error went away. Then I started getting this in the java console:
    Java exceptions - Pastebin.com

    I fixed that by editing going to jre7 and adding the following line to java.policy:
    permission java.util.PropertyPermission "file.encoding", "read";

    which isn't a feasible solution in an actual deployment situation, but at least I know it fixes that error. A little off-topic, if I don't want to sign the jar is there a way make it where the applet can access the mysql jdbc driver? I don't think I can include it in the jar as it is GPL and this could possibly go into a commercial app in the future..

    After that I quit getting strange errors and it went back to:
    SQL Exception: Communications Link Failure


    which is the same thing it would do in Eclipse if I don't have the MySQL server started or I have the wrong URL in the code. So now I'm guessing it is something to do with the MySQL server.. something like enabling TCP/IP or using a 192.168.x.x or xxx.xxx.xxx.xxx address, I don't know.
    Last edited by cplredhartsock; 03-03-2012 at 02:57 AM.

  4. #4
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: Is this a java issue? JApplet with MySQL access.. can't connect to mySQL

    Ok, so I figured out how to change the MySQL server instances properties, set it to allow all hosts and turned TCP/IP networking on. When running the applet from eclipse it connects on localhost and 192.168.0.10 (my local address). If I run the applet and try localhost, 192.168.0.10 or the external IP none of those work.
    I get this error exactly:

    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

    Also: I tried turning off my software firewall completely and forwarding port 3306, and it still did not work when embedded in a web page. Still works find from Eclipse even with the firewall running
    Last edited by cplredhartsock; 03-03-2012 at 04:26 AM.

  5. #5
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: Is this a java issue? JApplet with MySQL access.. can't connect to mySQL

    Ok, so I made three different jars of the program, each with a different IP address (localhost, the 192.168.x.x IP of my computer that the applet and the mysql server is on, and the external IP of my computer) for the MySQL server (which is running on localhost). I had the MySQL server enable TCP/IP, bind-address to 0.0.0.0 (accepting connections on all interfaces), and I started it with the --skip-grant-tables option. I forwarded port 3306 on my router and disabled my software firewall. Then I created a keystore with keytool and digitally signed each one of the jars. I tested each one of the jars and the applet will still not connect to the MySQL server on localhost. It connects perfectly fine within Eclipse. The only exception I ever get is that: SQL Exception Communications Link Failure.
    I have no java.security permissions stuff popping up or anything. I really have no idea why this is not working. What else could be wrong?

Similar Threads

  1. [MySQL Connector 5.1.6] Issue with Driver.connect()
    By soundlord in forum Java Applets
    Replies: 6
    Last Post: 07-02-2011, 01:33 AM
  2. how to connect java to mysql?
    By ranvir in forum JDBC
    Replies: 2
    Last Post: 12-11-2010, 08:34 AM
  3. Connectivity issue-MySQL and Java
    By Pragya in forum JDBC
    Replies: 9
    Last Post: 01-27-2010, 05:28 PM
  4. connect java with mysql in rhel5
    By niraj.vara in forum New To Java
    Replies: 0
    Last Post: 07-17-2009, 09:23 AM
  5. Replies: 2
    Last Post: 06-12-2008, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •