7 Replies Latest reply: Jul 30, 2009 8:06 AM by 843789 RSS

    Java Applets and Mysql

    843785
      Please some one hel me.

      I have a java project working on and Im am supposed to build an java applet that has a database application running in it. Im am using jsp pages to display applet. Howver I have a problem connecting to MYsql datbase remotely. the database is on the same machine as the Glassfish server which handles the application. When I run it on local mchine it works fine whn I try to run it on my laptop from the url the applet does not load and I get this exception.

      com.mysql.jdbc.exceptions.jdbc4.communicationsException:Communications link faliure

      This is the code to cnnect to database

      public MySQLTable(Object ObjectScreen)
      {
      try
      {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      this.con = DriverManager.getConnection("jdbc:mysql://ipaddress:" +
      "3306/ajpadatabase","username","password");

      }
      }

      please some one help me figure this out.

      Im wondering if it is the router my machine is behind. I have a Belkin wireless router and it gives a IPv4 address when I run IPConfig.
        • 1. Re: Java Applets and Mysql
          843785
          Is the mysql server on a private network? Is the machine running the applet on that same network?
          • 2. Re: Java Applets and Mysql
            843785
            Well the set up of the machines is that one is a desk top machine and one is a laptop. I have a wireless router that is connected directly to the lap top through the ethernet port and the laptop uses the Belkin wireless router as its access point for the internet. The problem is definetly the url for the connection string as I have tried setting up connection in netbeans using the MySql driver adapter on service interface however it does not connect and gives me the same message (com.mysql.jdbc.exceptions.jdbc4.ComunicationsException: Communications Link failure). I also tried using an online site that tells you your IP address but that does not work either.
            • 3. Re: Java Applets and Mysql
              843785
              Found out that when I turn off all firewalls on server machine it works. But that is not safe what else can I do to allow MYsql traffic without tuning off firewals.
              • 4. Re: Java Applets and Mysql
                843785
                I figured it out. Thanks for help guys. I just allowed all connections through the MYSQL port both TCP and UDP and the applet is working like a charm. My panic attack is done now.
                • 5. Re: Java Applets and Mysql
                  843789
                  Hi, Im having the same problem. Im trying to connect to the MySQL server of my web host. Plz let me know how u got your problem solved. Tks.
                  • 6. Re: Java Applets and Mysql
                    gimbal2
                    - connecting from an applet?


                    ( assuming the answer is yes: )

                    - is the applet downloaded from this same webhost? If not you cannot connect to the webhost; an applet is only allowed to open a connection to the host it was downloaded from.
                    - have you contacted the webhost to know what their security restrictions are? If for example they have to open up IP addresses to allow connections to the database, connecting from an applet is not going to work.
                    - have you checked your local firewall rules to see if it allows outgoing connections on the specific port you are trying to connect to?
                    • 7. Re: Java Applets and Mysql
                      843789
                      mahindasdfsdf wrote:
                      Hi, Im having the same problem. Im trying to connect to the MySQL server of my web host. Plz let me know how u got your problem solved. Tks.
                      This thread is a all a huge mistake. In almost all conditions you never want to connect directly to any database from an Applet. The only exception is if the applet is running in an intranet environment. This is because you will have to open your database to connections from any address and this will lead to your database being hacked.