简体   繁体   English

我无法从Google App Engine上已部署的后端Servlet连接到我的Google Cloud sql数据库

[英]I can't connect to my google cloud sql database from my deployed backend servlet on the google app engine

I have done everything that is required of me and my deployed backend servlet on the google app engine isn't making any connection to my google cloud database and the worst part of it, is that, my app engine log isn't even showing any error at all, its showing "POST /hello HTTP/1.1" 200 46... I seriously don't understand what is going on here for the past 5days.. 我已经完成了我所需的一切,而我在Google App Engine上部署的后端Servlet没有与我的Google Cloud数据库建立任何连接,而最糟糕的部分是,我的App Engine日志甚至没有显示任何内容。完全没有错误,显示为“ POST / hello HTTP / 1.1” 200 46 ...我真的不明白过去5天的情况。

these are the things i have done below: 这些是我在下面所做的事情:

This is my servlet code: 这是我的servlet代码:

 public class MyServlet extends HttpServlet {   
        @Override  
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {    
            resp.setContentType("text/plain");  
            resp.getWriter().println("Please use the form to POST to this url");  
        }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        String url = null;
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        try {
           if (SystemProperty.environment.value() ==
                   SystemProperty.Environment.Value.Production) {
              // Connecting from App Engine.

                // Load the class that provides the new "jdbc:google:mysql://" prefix.
            Class.forName("com.mysql.jdbc.GoogleDriver");
            url = "jdbc:google:mysql://festive-shark-90408:daily-joy-project/database?user=joys";

           } else {
                // Local MySQL instance to use during development.
             Class.forName("com.mysql.jdbc.Driver");
             url = "jdbc:mysql://<cloud-sql-instance-ip>:3306/database?user=joys";

                // Alternatively, connect to a Google Cloud SQL instance using:

           }
        } catch (Exception e) {
            e.printStackTrace();

        }


        try {
            Connection conn = DriverManager.getConnection(url);
            try {

                String fname = req.getParameter("name");
              //  String content = req.getParameter("message");


                    String statement = "INSERT INTO message (tags, posts, date, datetime) VALUES( ? , 'message', now(), now() )";
                    PreparedStatement stmt = conn.prepareStatement(statement);
                    stmt.setString(1, fname);
                   // stmt.setString(2, content);
                    int success = 2;
                    success = stmt.executeUpdate();
                    if (success == 1) {
                        out.println(
                                "<html><head></head><body>Success! Redirecting in 3 seconds...</body></html>");
                    } else if (success == 0) {
                        out.println(
                                "<html><head></head><body>Failure! Please try again! " +
                                        "Redirecting in 3 seconds...</body></html>");
                    }



            } finally {
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }



    }

    }

In my appengine-web.xml, below are the parameters: 在我的appengine-web.xml中,以下是参数:

application value: festive-shark-90408 应用价值:Celebration-shark-90408

version value: app-001 版本值:app-001

threadsafe value: true 线程安全值:true

use-google-connector-j value: true use-google-connector-j值:true

system-properties: 系统属性:

    property name="java.util.logging.config.file" value="WEB-INF/logging.properties" 

My android studio is using the JDK 1.7.0_72 我的Android Studio使用的是JDK 1.7.0_72

My appengine sdk is appengine-java-sdk-1.9.18 我的appengine sdk是appengine-java-sdk-1.9.18

I have set the Access control in my cloud sql to authorize my app engine application and also to authorize my network ip. 我已经在我的云SQL中设置了访问控制,以授权我的App Engine应用程序并授权我的网络IP。

I already deployed my backend servlet successfully, whenever I make a post request to the servlet, my app engine log shows ONLY this: 我已经成功部署了后端Servlet,无论何时向Servlet发出发布请求,我的应用引擎日志都只会显示以下内容:

203.106.176.214 - - [04/Apr/2015:04:43:17 -0700] "POST /hello HTTP/1.1" 200 45 - "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36" "festive-shark-90408.appspot.com" ms=39 cpu_ms=76 cpm_usd=0.000005 instance=00c61b117c0b660d29c1e893219b346d423915 app_engine_release=1.9.18 203.106.176.214--[04 / Apr / 2015:04:43:17 -0700]“ POST / hello HTTP / 1.1” 200 45-“ Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 537.36(KHTML,like Gecko )Chrome / 41.0.2272.118 Safari / 537.36“” festive-shark-90408.appspot.com“ ms = 39 cpu_ms = 76 cpm_usd = 0.000005实例= 00c61b117c0b660d29c1e893219b346d423915 app_engine_release = 1.9.18

Meaning it was successfully because status code 200.. 表示成功,因为状态码为200。

My cloud sql database isn't being queried at all after this, but whenever I run the server locally on my laptop, everything works fine and my cloud sql gets the connection. 此后根本不查询我的cloud sql数据库,但是每当我在便携式计算机上本地运行服务器时,一切正常,并且cloud sql得到连接。

It just doesn't work with my app engine. 它只是不适用于我的应用程序引擎。

WHY? 为什么? I really don't understand where the problem is coming from. 我真的不明白问题出在哪里。

I figured out what was wrong.. 我弄清楚出了什么问题..

First, I was meant to use root as my username when connecting to the cloud sql database from the app engine. 首先,从应用程序引擎连接到Cloud SQL数据库时,我本打算使用root作为用户名。

Secondly, I was meant to change the App Engine Project Title from its default name to a name i want to give it.. (I still don't know why this is affecting it) 其次,我本打算将App Engine项目标题从其默认名称更改为我想要赋予的名称。(我仍然不知道为什么这会影响它)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google APP Engine 和云 sql :: 无法在 Google 云 sql(我的 sql)中连接 Spring boot 应用程序 - Google APP Engine and cloud sql :: Unable to connect Spring boot app in Google cloud sql (my sql) 无法通过Google App Engine Servlet(Java)将对象存储在Google Cloud Storage中 - Cannot store objects in my Google Cloud Storage from my Google App Engine Servlet (Java) 部署后的Google App Engine和Cloud SQL - Google App Engine and Cloud SQL when deployed Spring 启动应用程序在部署到 Google App Engine 时无法连接到 Google Cloud SQL (PostgreSQL) - Spring Boot app can't connect to Google Cloud SQL (PostgreSQL) when deploying to Google App Engine 无法从Google App Engine(春​​季启动应用)连接到Google Cloud SQL(第二代) - Can not connect to google cloud sql(second generation) from google app engine(spring boot app) 如何从服务器端(Google App Engine,Cloud Endpoints)向我的客户端发送信息? - How can I send from the server-side (Google App Engine, Cloud Endpoints) the information to my client? 将Google App Engine后端添加到我的应用程序 - Adding Google App Engine Backend to my App 使用Google App Engine端点连接到Cloud SQL - Connect to Cloud SQL with Google App Engine Endpoint 如何为我在Google App Engine上部署的应用程序的Chrome插件绑定插件令牌 - How can I bind plugin token with my chrome plugin for the application deployed on Google App Engine Google App Engine后端servlet没有响应 - Google App Engine backend servlet not responding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM