Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet + JDBC + MySQL = Unable to connect

843842Aug 31 2009 — edited Aug 31 2009
I've searched the forums, searched Google for hours, and I'm unable to find an answer to this problem. When I find a post explaining my problem exactly, no one responds.

I'm trying to connect to a MySQL (5.0.67-0ubuntu6) server running on Ubuntu 8.10. Don't see how this would be relevant but just in case, I'm using JK (Apache Tomcat Connector) to connect Tomcat with Apache, and I'm using DWR (Direct Web Remoting) which is how I'm communicating with the Servlet.

Now heres the problem, I'm trying to connect to a MySQL server (as stated above) and I'm getting the following exception:
Server connection failure during transaction. Due to underlying exception: 'java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)'.

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)

STACKTRACE:

java.net.SocketException: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
    at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:407)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:268)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2921)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:222)
    at dwr.esign.ESign.getAgreement(ESign.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
    at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
    at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
    at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
    at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    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:269)
    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:301)
    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)\n\tat 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:293)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:636)


** END NESTED EXCEPTION **


Attempted reconnect 3 times. Giving up.
The code:
Connection conn;
try {
    Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
    conn = DriverManager.getConnection( "jdbc:mysql://" + db_host + "/" + db_name + "?autoReconnect=true&user=" + db_user + "&password=" + db_pass );
} catch ( SQLException ex ) {
    System.out.println( "Error: " + ex.getMessage() );
}
Note: I put the System.out.println() in the Catch() as an example, I'm actually returning the error so it can be sent to the browser (thanks to DWR).

I was originally using the 5.1.8 mysql-connector jar and I wasn't getting a stack trace like that at all, once I changed to 5.0.8 I got that stack trace.

This problem is driving me crazy, and I have a feeling it's going to be something very simple that I'm not realizing. Also, to get around all the "it's a network issue", not only is tomcat & mysql on the same server, but if I created a regular java application with the SAME exact code it connects just fine. It seems to only be a problem when connecting from tomcat, but I'm not exactly sure why.

Any help would be GREATLY appreciated.

Thanks in advanced.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2009
Added on Aug 31 2009
5 comments
2,047 views