Issues Resolved With

When I first set up the Tomcat 5.5 server on my tinkering box, I can into security issues with getting the dumb programs to connect to the MySQL server – even on localhost. Thanks to the Java community, I found my answer an answer was provided for me.

I got the errors when I moved the web app from my pc to that server with the MySQL database to see it on the Internet. The Tomcat server did on the problem computer. I have successfully ran a servlet w/o MySQL functionality. Below is the exception output when I tried to connect to the DB:

Communications link failure due to underlying exception:** BEGIN NESTED EXCEPTION **
MESSAGE: access denied ( connect,resolve) access denied ( connect,resolve)
 at com.mysql.jdbc.StandardSocketFactory.connect(
 at com.mysql.jdbc.MysqlIO.(
 at com.mysql.jdbc.Connection.createNewIO(
 at com.mysql.jdbc.Connection.(
 at com.mysql.jdbc.NonRegisteringDriver.connect(
 at java.sql.DriverManager.getConnection(
 at java.sql.DriverManager.getConnection(
 at Query1.processRequest(
 at Query1.doGet(
 at javax.servlet.http.HttpServlet.service(
 at javax.servlet.http.HttpServlet.service(
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
 at java.lang.reflect.Method.invoke(
 at Method)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
 at org.apache.catalina.core.ApplicationFilterChain.access$0(
 at org.apache.catalina.core.ApplicationFilterChain$
 at Method)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(
 at org.apache.catalina.core.StandardWrapperValve.invoke(
 at org.apache.catalina.core.StandardValveContext.invokeNext(
 at org.apache.catalina.core.StandardPipeline.invoke(
 at org.apache.catalina.core.StandardContextValve.invokeInternal(
 at org.apache.catalina.core.StandardContextValve.invoke(
 at org.apache.catalina.core.StandardValveContext.invokeNext(
 at org.apache.catalina.core.StandardPipeline.invoke(
 at org.apache.catalina.core.StandardHostValve.invoke(
 at org.apache.catalina.core.StandardValveContext.invokeNext(
 at org.apache.catalina.valves.ErrorReportValve.invoke(
 at org.apache.catalina.core.StandardValveContext.invokeNext(
 at org.apache.catalina.core.StandardPipeline.invoke(
 at org.apache.catalina.core.StandardEngineValve.invoke(
 at org.apache.catalina.core.StandardValveContext.invokeNext(
 at org.apache.catalina.core.StandardPipeline.invoke(
 at org.apache.catalina.core.ContainerBase.invoke(
 at org.apache.coyote.tomcat5.CoyoteAdapter.service(
 at org.apache.jk.server.JkCoyoteHandler.invoke(
 at org.apache.jk.common.HandlerRequest.invoke(
 at org.apache.jk.common.ChannelSocket.invoke(
 at org.apache.jk.common.ChannelSocket.processConnection(
 at org.apache.jk.common.SocketConnection.runIt(
 at org.apache.tomcat.util.threads.ThreadPool$

** END NESTED EXCEPTION **Last packet sent to the server was 3 ms ago.

My issue was strictly with the Tomcat software on the production server because when I ran it within the bundled version from within NetBeans, it worked fine and dandy.

Turns out, it was a Catalina permissions issue. I had to grant the web app permission to connect to the database. The following code worked for me.

grant codeBase "file:${catalina.home}/webapps/WebTest1/-" {
permission "", "connect,resolve";

If you decide to use it, be sure to change the first line to the directory of your web application.

This entry was posted on Thursday, August 9th, 2007 at 5:27 pm and is filed under Java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

6 Responses to “Issues Resolved With”

malvinc October 14th, 2007 at 6:16 am

Solved the access problem which an application encounters when trying to connect to MySql Server by adding the above permission in the /etc/tomcat5/policy.d/04webapps.policy file in tomcat version 5.

MySql used was -5.0.24a-Debian_9ubuntu2.1-log

Andrew Wells October 14th, 2007 at 8:24 am

Yes, I forgot to mention which file that code belongs in. Glad you had success with it.

Germ111 November 1st, 2007 at 10:47 am


Thanks so much for the solution. This was exactly my problem. I’d been messing with wrong policy files and this worked like a charm. I was able to get by with localhost.

grant codeBase “file:${catalina.home}/webapps/dbapp/-” {
permission “localhost:3306″, “connect,resolve”;

Andrew Wells November 1st, 2007 at 11:11 am

Thanks for posting your solution, Germ111. I’m glad I was able to help.

Leandro February 27th, 2009 at 9:17 am

Thanks guys!! That hint just saved my life!!!!

Thanks so much!!!

rama October 27th, 2009 at 2:05 am

Thanks for posting this solution. you made my life easy. I got jsp to connect to mysql database in tomcat but I am still getting the same error when I am executing same jsp through netbeans.

Leave a Reply