简体   繁体   English

谷歌云sql没有与我的项目(Java)连接

[英]Google cloud sql not connected with my project(Java)

LoginAuthServlet.java LoginAuthServlet.java

            Class.forName("com.mysql.jdbc.GoogleDriver");
            String url="jdbc:google:mysql://Instance_connection_name/dbname?user=xyz&password=abc";
            Connection conn = DriverManager.getConnection(url);

            String query = "SELECT  "
                        + "  * "
                        + " FROM "
                        + "  users "
                        + " WHERE "
                        + "   user_username = ? AND user_password = ? AND user_status = '1' "
                        /*+ "     user_type = ? "*/
                        + " limit 0,1";
                PreparedStatement stmtLogin = conn.prepareStatement(query);
                stmtLogin.setString(1, username);
                stmtLogin.setString(2, userPassword);

                ResultSet resource = stmtLogin.executeQuery();
                if(resource.next()){
                        HttpSession sess = req.getSession();
                        sess.setAttribute("isLogin", "true");

                        sess.setAttribute("userId", resource.getString("user_id"));
                        sess.setAttribute("userName", resource.getString("user_username"));
                        sess.setAttribute("userType", resource.getString("user_type"));
                        sess.setMaxInactiveInterval(30*60);
                        resp.sendRedirect("BusinessList.jsp"); 
                    }

appengine-web.xml AppEngine上-web.xml中

 <use-google-connector-j>true</use-google-connector-j> 

When i deploy this project and attempt to login then give response is {}..... i included all the jar file and if i am try to connect locally with IPV4 address then it work well,but if i deploy project then it's not work,i done all the things but my project can't connect with google cloud sql. 当我部署这个项目并尝试登录然后给出响应是{} .....我包括所有的jar文件,如果我尝试在本地连接IPV4地址然后它运作良好,但如果我部署项目然后它不是工作,我做了所有的事情,但我的项目无法与谷歌云sql连接。

If you are using a second generation instance, in order to connect from appengine you also need to include the region JDBC url like below: 如果您使用的是第二代实例,为了从appengine连接,您还需要包含区域JDBC url,如下所示:

String url="jdbc:google:mysql://[PROJECT-ID]:[REGION]:[INSTANCE-NAME]/dbname?user=xyz&password=abc";

Here they provide some example: https://cloud.google.com/appengine/docs/java/cloud-sql/ 这里他们提供了一些示例: https//cloud.google.com/appengine/docs/java/cloud-sql/

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

相关问题 使用Java连接到Google Cloud SQL - Connecting to Google Cloud SQL with Java 如何将连接到 SQL 管理服务器数据库的 java NetBeans 项目转移到另一台计算机? - How can I transfer my java NetBeans project connected to SQL management server database to another computer? 结合使用Java和Google Cloud SQL服务 - Using Java with a Google Cloud SQL service 如何为 Google Cloud SQL 配置 Java Hibernate? - How to configure Java Hibernate for Google Cloud SQL? google-cloud端点应用程序引擎连接的android项目的登台服务器 - staging server for google-cloud endpoint app-engine connected android project 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) 如何将 java 项目的 Maven 工件部署/托管到 Google Cloud Storage? - How to deploy/host the maven artifact of a java project to Google Cloud Storage? 创建 Google Cloud Bucket (Java API) 时未找到项目参数 - Project Parameter Not Found when Creating Google Cloud Bucket (Java API) Google Cloud Platform Java-Maven Deploy针对错误的项目 - Google Cloud Platform Java - Maven Deploy targets wrong project 连接到Cloud SQL上的postgresql实例:未为项目启用Google Cloud SQL API - Connect to postgresql instance on Cloud SQL: The Google Cloud SQL API is not enabled for project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM