gpt4 book ai didi

mysql - tomcat 移植到 Google App Engine

转载 作者:行者123 更新时间:2023-11-29 08:36:32 32 4
gpt4 key购买 nike

我当时的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://

最佳答案

回答你的问题,是的,这肯定会导致失败。

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

事情是这样的:

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

参见:this AppEngine guide了解完整的步骤。

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

关于mysql - tomcat 移植到 Google App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15058286/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com