Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To start, the following exception</p> <pre>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure</pre> <p>can have the following causes:</p> <ol> <li>IP address or hostname in JDBC URL is wrong.</li> <li>Hostname in JDBC URL is not recognized by local DNS server.</li> <li>Port number is missing or wrong in JDBC URL.</li> <li>DB server is down.</li> <li>DB server doesn't accept TCP/IP connections.</li> <li>DB server has run out of connections.</li> <li>Something in between Java and DB is blocking connections, e.g. a firewall or proxy. </li> </ol> <hr> <p>Further, do you <em>realize</em> that an Java Applet physically runs at the <strong>client</strong> machine? I.e. the machine where the webbrowser runs. The client basically downloads the applet from the webserver and it get executed at client (local) machine. The JDBC connection string <code>jdbc:mysql://localhost:3306</code> would try to connect to a MySQL database running at the very same machine as where the applet runs. You can't reasonably expect that every client on the world will run a MySQL DB, let alone with <em>your</em> database/table.</p> <p>If all you want is to access the MySQL server hosted at the server machine (there where the webserver runs) and you want to let the applet communicate with it, then you really have to create and run a <em>webservice</em> at the webserver. Since you tagged this question with <code>[PHP]</code> as well, I guess that you're using PHP at the server side, in that case, just create a PHP script which executes the MySQL action accordingly based on the request parameters or pathinfo and returns the MySQL results as for example a <a href="http://php.net/manual/en/function.json-encode.php" rel="nofollow noreferrer">JSON</a> or XML string. In the Applet, you can use the Java SE builtin <a href="https://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests"><code>java.net.URLConnection</code></a> or the more convenienced <a href="http://hc.apache.org/httpcomponents-client/" rel="nofollow noreferrer">Apache HttpComponents Client</a> to communicate with the webserver. E.g.</p> <pre><code>URLconnection connection = new URL(getCodeBase(), "script.php?action=getdetails&amp;productid=1").openConnection(); InputStream response = connection.getInputStream(); // ... </code></pre> <p>In Java, you could process any JSON response using <a href="https://stackoverflow.com/questions/1688099/converting-json-to-java/1688182#1688182">Google Gson</a> any XML response using JAXP.</p> <hr> <p>That said (and <em>unrelated</em> to the current problem), the JDBC driver name you're using is the <strong>deprecated</strong> <code>org.gjt.mm.mysql.Driver</code>. I strongly recommend to use the correct driver name which was introduced over a decade ago to replace the old driver name: <code>com.mysql.jdbc.Driver</code>. Further, the <code>Class#newInstance()</code> call after <code>Class#forName()</code> is also not needed. It was to workaround a <em>bug</em> in the old driver. Also see <a href="https://stackoverflow.com/questions/2092659/what-is-difference-between-class-forname-and-class-forname-newinstance/2093236#2093236">this explanation</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload