0

我原来有期webservice的tomcat服务器。现在我想分段webservice移植到GAE。我移植成功了。执行,但显示此错误消息。这会导致出错的可能性吗?

我的代码:

 public class LOAD extends HttpServlet{
        static String JBx;
        static String JBy;
        static String JBSx;
        static String JBSy;
        static String gps;
        String a;
        int i;
          private Connection con = null; //Database objects 
          private Statement stat = null; 
          private ResultSet rs = null; 
          private PreparedStatement pst = null; 
        private String dropdbSQL = "DROP TABLE User "; 

      private String createdbSQL = "CREATE TABLE User (" + 
        "    id     INTEGER " + 
        "  , name    VARCHAR(20) " + 
        "  , passwd  VARCHAR(20))"; 

      private String insertdbSQL = "insert into User(id,gps,recopy) " + 
              "select ifNULL(max(id),0)+1,?,? FROM User"; 

      private String selectSQL = "select * from User "; 
      public static void main(String[] args) 
      { 


      } 
          public void SelectTable() 
          { 
            try 
            { 
              stat = con.createStatement(); 
              rs = stat.executeQuery(selectSQL); 
              while(rs.next()) 
              { 
                 JBSx =rs.getString("gps");
                 JBSx="<div id=dd>"+JBSx+"</div>";
                 if(JBx!=null){
                  JBx=JBx+JBSx;

                 }else
                 {
                     JBx=JBSx;

                 }
                     JBSy =rs.getString("recopy");
                     JBSy="<div id=ff>"+JBSy+"</div>";
                     if(JBy!=null){
                          JBy=JBy+JBSy;

                     }
                     else
                     {
                         JBy=JBSy;

                     }
              } 
            } 
            catch(SQLException e) 
            { 
              System.out.println("DropDB Exception :" + e.toString()); 
            } 
//          finally 
//          { 
//            Close(); 
//          } 
          } 

          private void Close() 
          { 
            try 
            { 
              if(rs!=null) 
              { 
                rs.close(); 
                rs = null; 
              } 
              if(stat!=null) 
              { 
                stat.close(); 
                stat = null; 
              } 
              if(pst!=null) 
              { 
                pst.close(); 
                pst = null; 
              } 
            } 
            catch(SQLException e) 
            { 
              System.out.println("Close Exception :" + e.toString()); 
            } 
          } 
      public LOAD() 
      { 
        try { 
          Class.forName("com.mysql.jdbc.Driver"); 
          con = DriverManager.getConnection( 
                  "jdbc:mysql://hl2dm.synology.me:3306/teama", 
                  "abc",""); 

        } 
        catch(ClassNotFoundException e) 
        { 
          System.out.println("DriverClassNotFound :"+e.toString()); 
        }
        catch(SQLException x) { 
          System.out.println("Exception :"+x.toString()); 
        } 

      }  
    public void doGet(HttpServletRequest rq, HttpServletResponse rp) 
                    throws ServletException, IOException{
    JBx=null;
     JBy=null;
    JBSx=null;
    JBSy=null;
        rq.setCharacterEncoding("UTF-8");
//       String gps = rq.getParameter("gps");

        LOAD test = new LOAD(); 
        test.SelectTable(); 
        HttpSession session = rq.getSession();
//session.invalidate();
//        session.removeAttribute("reportx");
        session.setMaxInactiveInterval(3600);      
        session.setAttribute("reportx",JBx);
        session.setAttribute("reporty",JBy);
        rp.sendRedirect(rp.encodeRedirectURL("LOADPOST"));
    }
    public void doPost(HttpServletRequest rq, HttpServletResponse rp) 
                    throws ServletException, IOException{
        doGet(rq, rp);
    }
}

错误消息:HTTP 错误 500

Problem accessing /LOAD. Reason:

    INTERNAL_SERVER_ERROR
Caused by:

java.lang.NullPointerException
    at a.b.c.LOAD.SelectTable(LOAD.java:52)
    at a.b.c.LOAD.doGet(LOAD.java:149)
    at a.b.c.LOAD.doPost(LOAD.java:160)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:409)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Powered by Jetty://
4

1 回答 1

2

要回答你的问题,是的,它会导致明确的失败。

AppEngine 上没有要连接的 MySql 实例。您需要改用 Google Cloud SQL。

它是这样的:

  DriverManager.registerDriver(new AppEngineDriver());
      con = DriverManager.getConnection("jdbc:google:rdbms://instance_name/guestbook");

请参阅: 此 AppEngine 指南以获取完整的步骤集。

注意:要将开发服务器与本地 MySQL 实例一起使用,请参阅https://developers.google.com/appengine/docs/java/cloud-sql/developers-guide#using_the_java_development_server

于 2013-02-25T01:10:32.090 回答