title: How do I get java applets to connect to a MySQL server? (Error resolution)
body: <p>I'm losing my mind. I've been trying to get a Java Applet working with MySQL, and can't seem to figure out this one problem:</p>
  
  <p>Code:</p>
  
  <pre><code>final String dbClassName = "com.mysql.jdbc.Driver";
  
  final String CONNECTION = "jdbc:mysql://127.0.0.1/db";
  
  Class.forName(dbClassName);
  
  Properties p = new Properties();
  
  p.put("user","&lt;me&gt;");
  
  p.put("password","&lt;pw&gt;");
  
  Connection c = DriverManager.getConnection(CONNECTION,p);
  </code></pre>
  
  <p>The MySQL database works. I can connect and do things on it with php. I can even run the above code without an applet on the command line, and it works. However, when I try to run it as an applet, things break, and I get the following error:</p>
  
  <p><img src="https://dl.dropbox.com/u/46245195/javabug.jpg" alt="Stupid error"></p>
  
  <p>The applet is served through a php file, and the part that loads the applet is below. I added the "archive=mysql.jar" part after some googling. The jar file is the mysql-connector-for-java-5.08. I'm not entirely sure my context is right, but without this, it gives another error, that jdbc can't be found:</p>
  
  <pre><code>echo("&lt;applet archive=mysql.jar code=Display.class width=2600 height=1600&gt;");
  echo("&lt;/applet&gt;");
  </code></pre>
  
  <p>After searching the internet, I found a lot of comments (such as: <a href="https://forums.oracle.com/forums/thread.jspa?threadID=1453871" rel="nofollow">https://forums.oracle.com/forums/thread.jspa?threadID=1453871</a>) which talked about adding stuff like:</p>
  
  <pre><code>grant codeBase "file:${catalina.base}/webapps/TestServlet/-" {
  permission java.net.SocketPermission "127.0.0.1:3306", "connect";
  };
  </code></pre>
  
  <p>I've tried to put variations of this into various places, but nothing has really worked. I'm guessing part of the reason, is I have no idea how to implement the above. For example, what is /webapps/?. I'm currently using AWS EC2, and I'm new to this whole thing. I am also using Tomcat 6.</p>
  
  <p>If anyone has any suggestions I'd really appreciate some help. Even work-around solutions... like if I can call php files from my applet to connect for me, and have the php files return info, that'd also be acceptable. Please try to be detailed in solutions - once again, I'm new to linux-related things.  </p>
  
  <p>Thank you!</p>