在GoogleAppEngine上遇到异常com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException

时间:2012-03-18 06:12:38

标签: java google-app-engine jdbc struts

我使用GoogleAppEngine作为我的服务器。我在struts框架上编写了一个简单的jdbc应用程序(使用sql作为我的数据库)。但不知道为什么我无法正常运行它。 这是我得到的例外......

 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

Here is the full error log that i got

     [java] com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
     [java]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     [java]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
     [java]         at java.lang.reflect.Constructor.newInstance(Unknown Source)
     [java]         at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:116)
     [java]         at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:124)
     [java]         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
     [java]         at com.mysql.jdbc.Util.getInstance(Util.java:386)
     [java]         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
     [java]         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
     [java]         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
     [java]         at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
     [java]         at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2412)
     [java]         at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
     [java]         at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
     [java]         at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
     [java]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     [java]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
     [java]         at java.lang.reflect.Constructor.newInstance(Unknown Source)
     [java]         at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:116)
     [java]         at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:124)
     [java]         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
     [java]         at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
     [java]         at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
     [java]         at java.sql.DriverManager.getConnection(Unknown Source)
     [java]         at java.sql.DriverManager.getConnection(Unknown Source)
     [java]         at com.cac.struts.InsertMethod.<init>(InsertMethod.java:19)
     [java]         at com.cac.struts.InsertAction.execute(InsertAction.java:23)
     [java]         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
     [java]         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
     [java]         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
     [java]         at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
     [java]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
     [java]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     [java]         at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
     [java]         at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
     [java]         at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
     [java]         at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
     [java]         at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
     [java]         at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
     [java]         at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
     [java]         at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
     [java]         at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:363)
     [java]         at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
     [java]         at org.mortbay.jetty.Server.handle(Server.java:326)
     [java]         at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
     [java]         at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
     [java]         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
     [java]         at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
     [java]         at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
     [java]         at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
     [java]         at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
     [java] Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve)
     [java]         at java.security.AccessControlContext.checkPermission(Unknown Source)
     [java]         at java.security.AccessController.checkPermission(Unknown Source)
     [java]         at java.lang.SecurityManager.checkPermission(Unknown Source)
     [java]         at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:252)
     [java]         at java.lang.SecurityManager.checkConnect(Unknown Source)
     [java]         at java.net.InetAddress.getAllByName0(Unknown Source)
     [java]         at java.net.InetAddress.getAllByName0(Unknown Source)
     [java]         at java.net.InetAddress.getAllByName(Unknown Source)
     [java]         at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:247)
     [java]         at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
     [java]         at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2333)
     [java]         at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
     [java]         ... 51 more
     [java] java.lang.NullPointerException
     [java]         at com.cac.struts.InsertMethod.insert(InsertMethod.java:33)
     [java]         at com.cac.struts.InsertAction.execute(InsertAction.java:24)
     [java]         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
     [java]         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
     [java]         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
     [java]         at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
     [java]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
     [java]         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     [java]         at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
     [java]         at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
     [java]         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
     [java]         at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
     [java]         at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
     [java]         at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
     [java]         at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
     [java]         at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
     [java]         at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
     [java]         at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
     [java]         at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:363)
     [java]         at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
     [java]         at org.mortbay.jetty.Server.handle(Server.java:326)
     [java]         at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
     [java]         at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
     [java]         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
     [java]         at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
     [java]         at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
     [java]         at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
     [java]         at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

这是我尝试过的Model类代码

package com.cac.struts;
import java.sql.*;
/**
 *
 * @author hablu
 */
public class InsertMethod {
    Connection con=null;
    public InsertMethod()
    {
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
            //Class.forName("oracle.jdbc.driver.OracleDriver");
            //con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public boolean insert(int regd)
    {
        boolean b=false;
        try
        {
            PreparedStatement ps=con.prepareStatement("select * from student where regd=?");
            ps.setInt(1,regd);
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
                b=true;
                System.out.println("....."+rs.getString(1));
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return b;
    }
}

2 个答案:

答案 0 :(得分:0)

您的连接网址是什么?你在正确的港口连接?你可以发布一些代码吗?Mysql通常在3306端口上运行。

答案 1 :(得分:0)

谷歌应用引擎 - 谷歌的平台即服务工具 - 默认情况下不启用连接到关系数据库;相反,它提供了一个No-SQL DataStore(称为Bigtable)。

现在,Google正在测试GAE应用程序的RDBMS产品,并将其作为MySQL数据库实现。如果您是该服务的测试人员,则应使用Google的MySQL驱动程序(com.google.appengine.api.rdbms.AppEngineDriver)及其相应的JDBC连接URL(格式为jdbc:google:rdbms:// instance_name /留言)。更多信息here