为什么googleappengine mysql jdbc url不与数据库连接?

dohp0rv5  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(279)

我正在开发一个网站,其中有一个register.jsp页面。registrationservlet.java从register.jsp获取详细信息,并将所有详细信息存储到我的gcloud数据库表“users”中。问题是在部署之后,它不会将任何数据存储到数据库中。如果我在本地运行它,它会将数据存储在本地数据库中。但我不明白为什么数据没有存储在云数据库中。
注意:我遵循的正式文件,这不是一个maven项目。
下面是registrationservlet.javacode:-

@WebServlet({"/RegistrationServlet"})
public class RegistrationServlet
  extends HttpServlet
{
  private static final long serialVersionUID = 1L;

  public RegistrationServlet() {}

  protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {}

  protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    PrintWriter out = response.getWriter();

    String first_name = request.getParameter("f1");
    String last_name = request.getParameter("l1");
    String phone = request.getParameter("p1");
    String email = request.getParameter("e1");
    String uname = request.getParameter("uname");
    String user_dob = request.getParameter("udate");
    String password = request.getParameter("pwd");

    UserData ud = new UserData();

    ud.setFirst_name(first_name);
    ud.setLast_name(last_name);
    ud.setUname(uname);
    ud.setPhone(phone);
    ud.setEmail(email);
    ud.setUser_dob(user_dob);
    ud.setPassword(password);

    if ((first_name.isEmpty()) || (last_name.isEmpty()) || (phone.isEmpty()) || (email.isEmpty()) || (password.isEmpty())) {
      RequestDispatcher rd = request.getRequestDispatcher("Register.jsp");
      out.println("<font color=red>Please fill all the fields</font>");
      rd.include(request, response);
    }
    else
    {
      try {
        Class.forName("com.mysql.jdbc.Driver");
      }
      catch (ClassNotFoundException e) {
        e.printStackTrace();
      }

      System.out.println("Connecting to the Database");

      try
      {
        Connection con = DriverManager.getConnection("jdbc:mysql://google/my_database_name?cloudSqlInstance=my_instance_connection_name&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=root&password=my_password&useSSL=false");

System.out.println("Connected to the Database");
        String query = "insert into liveinbliss.users values(?,?,?,?,?,?,?)";

        PreparedStatement ps = con.prepareStatement(query);

        ps.setString(1, first_name);

        ps.setString(2, last_name);

        ps.setString(3, uname);

        ps.setString(4, phone);

        ps.setString(5, email);

        ps.setString(6, user_dob);

        ps.setString(7, password);

        ps.executeUpdate();

        System.out.println("successfuly inserted");

        ps.close();

        con.close();

      }
      catch (SQLException e)
      {

        e.printStackTrace();
      }
      HttpSession session = request.getSession();
      session.setAttribute("username", first_name);
      response.sendRedirect("Success.jsp");

    }
  }
}

下面是错误log:-

Oct 07, 2018 9:05:54 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties
INFO: Overwriting system property key 'java.util.logging.config.file', value '/Users/shashankk/Library/Application Support/google-cloud-tools-java/managed-cloud-sdk/LATEST/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/config/sdk/logging.properties' with value 'WEB-INF/logging.properties' from '/Users/shashankk/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/LIB/WEB-INF/appengine-web.xml'
2018-10-07 21:05:54.926:INFO::main: Logging initialized @889ms
2018-10-07 21:05:55.430:INFO:oejs.Server:main: jetty-9.3.18.v20170406
2018-10-07 21:05:58.040:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=2389ms
2018-10-07 21:05:58.439:INFO:oejsh.ContextHandler:main: Started c.g.a.t.d.j.DevAppEngineWebAppContext@1e04fa0a{/,file:///Users/shashankk/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/LIB/,AVAILABLE}{/Users/shashankk/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/LIB}
2018-10-07 21:05:58.451:INFO:oejs.AbstractConnector:main: Started NetworkTrafficSelectChannelConnector@21e360a{HTTP/1.1,[http/1.1]}{localhost:8080}
2018-10-07 21:05:58.465:INFO:oejs.Server:main: Started @4428ms
Oct 07, 2018 3:35:58 PM com.google.appengine.tools.development.jetty9.JettyContainerService startHotDeployScanner
INFO: Full scan of the web app in place every 1s.
Oct 07, 2018 3:35:58 PM com.google.appengine.tools.development.AbstractModule startup
INFO: Module instance default is running at http://localhost:8080/
Oct 07, 2018 3:35:58 PM com.google.appengine.tools.development.AbstractModule startup
INFO: The admin console is running at http://localhost:8080/_ah/admin
Oct 07, 2018 9:05:58 PM com.google.appengine.tools.development.DevAppServerImpl doStart
INFO: Dev App Server is now running
Oct 07, 2018 9:06:01 PM com.google.appengine.tools.development.jetty9.LocalResourceFileServlet doGet
WARNING: No file found for: /dist/css/bootstrap.min.css
Oct 07, 2018 9:06:01 PM com.google.appengine.tools.development.jetty9.LocalResourceFileServlet doGet
WARNING: No file found for: /signin.css
Connecting to the Database
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception: 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.Util.getInstance(Util.java:408)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
    at com.mysql.jdbc.MysqlIO.createSocketFactory(MysqlIO.java:3333)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2197)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at controller.RegistrationServlet.doPost(RegistrationServlet.java:84)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.appengine.tools.development.jetty9.StaticFileFilter.doFilter(StaticFileFilter.java:123)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
    at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at com.google.appengine.tools.development.DevAppServerRequestLogFilter.doFilter(DevAppServerRequestLogFilter.java:44)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1751)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
    at com.google.appengine.tools.development.jetty9.DevAppEngineWebAppContext.doScope(DevAppEngineWebAppContext.java:94)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at com.google.appengine.tools.development.jetty9.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:601)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at org.eclipse.jetty.server.Server.handle(Server.java:534)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.sql.mysql.SocketFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:239)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.mysql.jdbc.MysqlIO.createSocketFactory(MysqlIO.java:3331)
    ... 61 more
Oct 07, 2018 9:06:42 PM com.google.appengine.tools.development.jetty9.LocalResourceFileServlet doGet
WARNING: No file found for: /dist/css/bootstrap.min.css
Oct 07, 2018 9:06:42 PM com.google.appengine.tools.development.jetty9.LocalResourceFileServlet doGet
WARNING: No file found for: /signin.css
Oct 07, 2018 9:06:42 PM com.google.appengine.tools.development.jetty9.LocalResourceFileServlet doGet
WARNING: No file found for: /dashboard.css

谢谢您

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题