App Engine Java Servlet不连接到Cloud SQL [英] App Engine Java Servlet does not connect to Cloud SQL

查看:90
本文介绍了App Engine Java Servlet不连接到Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用app引擎创建了一个java web servlet,servlet向数据库发出请求。我已经使用本地数据库在本地测试了这个servlet,并且它工作得很好,然后我在本地测试了这个servlet,但是却访问了Cloud SQL数据库,这也很完美。

我部署servlet后出现问题。一旦部署完毕,所有数据库请求将返回以下内容:

  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败

成功发送到服务器的最后一个数据包是0毫秒前。驱动程序没有
从服务器收到任何数据包。

我在云控制台中进行了检查,并且我的应用程序已正确添加到云SQL授权应用程序引擎应用程序在访问控制选项卡下。



有没有人与部署的应用程序引擎servlet有类似的问题?任何解决方案或建议在那里?我会很感激任何和所有的帮助!!!

更新:



上面的错误是使用下面的代码来访问db生成的。 ;
Url =jdbc:mysql://< ip-address-cloudsql>:3306 /< dbname>;
Connection con = DriverManager.getConnection(Url,root,< password>);

使用此代码获得相同的错误,请注意,它与代码中显示的代码非常相似例如 https://developers.google.com/appengine/docs/java / cloud-sql /

  Class.forName(com.mysql.jdbc.GoogleDriver); 
Url =jdbc:google:mysql://< appID:instanceID> /< dbname> ;?
user = root& password =< password>;
Connection con = DriverManager.getConnection(Url);

我使用appid和实例来设置url,然后在这个stackoverflow帖子中显示格式化提示id:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:



使用此代码导致以下不同的错误:

  java.sql.SQLException:访问被用户'root'拒绝@'localhost'(使用密码:YES)

我假设它说本地主机,因为我的cloudsql数据库设置为遵循应用程序引擎servlet。另外,要知道当在本地运行servlet并访问云sql数据库时,这两种方法都能正常工作。

有什么想法?我不知道还有什么可以尝试的:[/ b>]

解决方案

从授权的App Engine应用程序连接到Cloud SQL时, (实际上,如果你尝试连接密码,它会失败)。



将连接字符串更改为 jdbc:google:mysql:/ /< APPID:实例ID> /< DBNAME> ;?
user = root
省略& password =< password> 部分

I have created a java web servlet using app engine, the servlet makes requests to a database. I have tested the servlet locally using a local database and it worked perfectly, i then proceeded to test the servlet locally but istead accessed the Cloud SQL database, this also worked perfectly.

My problem arises after i deploy the servlet. Once deployed all database requests return the following:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not 
received any packets from the server.

I checked within the cloud console, and my app was properly added to the cloud SQL Authorized App Engine Applications under the Access Control tab.

Has anyone had similar problems with deployed app engine servlets? Any solutions or advice out there? I would appreciate any and all help!!!

UPDATE:

The above error was generated using the following code to access the db

Class.forName("com.mysql.jdbc.Driver");
Url = "jdbc:mysql://<ip-address-cloudsql>:3306/<dbname>";
Connection con = DriverManager.getConnection (Url,"root",<password>);

the same error was acheived using this code, note that it is very similar to the code shown in the example here https://developers.google.com/appengine/docs/java/cloud-sql/

Class.forName("com.mysql.jdbc.GoogleDriver");
Url = "jdbc:google:mysql://<appID:instanceID>/<dbname>? 
user=root&password=<password>";
Connection con = DriverManager.getConnection (Url);

I followed the formatting tips show in this stackoverflow post when it came to setting the url using appid and instance id: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

Using this code resulted in the following different error:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

I'm assuming it says localhost because my cloudsql database is set to follow the app engine servlet. Also, know that both of these methods worked fine when running the servlet locally and accessing the cloud sql database.

any thoughts? i don't know what else to try:[

解决方案

When connecting to Cloud SQL from an authorized App Engine application, the password is not required (actually it will fail if you try to connect with password).

Change your connection string to jdbc:google:mysql://<appID:instanceID>/<dbname>? user=root omitting the &password=<password> part

这篇关于App Engine Java Servlet不连接到Cloud SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆