2012-03-18 57 views
0

我使用GoogleAppEngine作爲我server.I已經(使用SQL作爲我的數據庫)編寫的Struts框架的一個簡單的JDBC應用。但不知道爲什麼我無法正確運行它。 下面是我得到的例外......有一個例外com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException上GoogleAppEngine

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) 

這裏是模型類的代碼,我已經嘗試

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; 
    } 
} 
+1

應該張貼,讓你您的數據庫連接 – 2012-03-18 07:31:44

+0

我haved編輯我的職務,並添加了JDBC類模型的代碼。 – Hablu 2012-03-19 00:57:48

回答

0

什麼是你的連接網址?你正在連接正確的端口嗎? ?你可以張貼一些代碼Mysql的通常運行在端口3306

+0

我編輯了我的文章並添加了jdbc類模型。 – Hablu 2012-03-19 00:58:30

+0

您的連接網址錯誤。它應該包含如下所示的端口:jdbc:mysql:// localhost:3306/test – sachinrahulsourav 2012-03-19 03:40:50

0

谷歌應用程序引擎從Google- -the平臺作爲一種服務的工具,默認情況下不能夠連接到一個關係數據庫;相反,它提供了一個No-SQL DataStore(稱爲Bigtable)。

現在,谷歌是在beta測試一個RDBMS祭GAE應用,MySQL數據庫來實現。如果你是該服務的測試,你應該使用谷歌的MySQL驅動程序(com.google.appengine.api.rdbms.AppEngineDriver)及其相應的JDBC連接URL(JDBC中的格式:谷歌:RDBMS:// INSTANCE_NAME /留言)。更多信息here

相關問題