title: Tomcat 6 and MySQL 5.x connection error on Ubuntu
body: <p>When attempting to connect to a MySQL 5.x database in a JSP webapplication running on Tomcat 6, I am getting the following exception:</p>
  
  <pre><code>org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
  
  ** BEGIN NESTED EXCEPTION ** 
  
  java.net.SocketException
  MESSAGE: java.security.AccessControlException: access denied (java.net.SocketPermission [0:0:0:0:0:0:0:1]:3307 connect,resolve)
  
  STACKTRACE:
  
  java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission [0:0:0:0:0:0:0:1]:3307 connect,resolve)
      at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:151)
      at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:280)
      at com.mysql.jdbc.Connection.createNewIO(Connection.java:1699)
      at com.mysql.jdbc.Connection.&lt;init&gt;(Connection.java:405)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268)
      at java.sql.DriverManager.getConnection(DriverManager.java:620)
      at java.sql.DriverManager.getConnection(DriverManager.java:200)
      at org.apache.jsp.doLogin_jsp._jspService(doLogin_jsp.java:70)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:616)
      at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAsPrivileged(Subject.java:537)
      at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
      at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)
      at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:56)
      at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:636)
  </code></pre>
  
  <p>What could be the cause and how can I fix it?</p>