com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: [英] com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

查看:181
本文介绍了com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个谷歌应用程序引擎连接项目,我试图连接到谷歌云数据库。我上传我的项目到谷歌,并通过它尝试连接到数据库。



我的连接URL如下 - >

  Class.forName(com.mysql.jdbc。 GoogleDriver); 
String password =;
url =jdbc:google:mysql:// my-project-id:my-instance-name / dbname?user = root& password =+ password +useUnicode = true& characterEncoding = UTF-8;

连接conn = DriverManager.getConnection(url);

这是我尝试获取URL的连接的地方,我得到一个异常

  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败成功发送到服务器的最后一个数据包是0毫秒前。驱动程序尚未收到来自服务器的任何数据包。 

然后我将以下字符串添加到我的url->
& autoReconnect = true& failOverReadOnly = false& maxReconnects = 10

然后收到另一个异常 - >

  com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接。试图重新连接10次。放弃。 

我已经尝试了ping数据库实例的IP地址,它工作正常。 b
$ b

我需要在我的云计算实例中给出任何显式权限才能连接吗?



欢迎任何建议。

奇怪的是,我可以使用eclipse连接到数据库,通过使用project-> google-> app engine-> usegoogle云sql实例 - > configure.I在这里使用与代码中的url相同的用户名(root)和密码(),但由于某种原因它拒绝通过代码进行连接。
我也启用了

 < use-google-connector-j> true< / use-google-连接器-J> 

标记在我的
appengine-web.xml中



我将根密码从更改为某个值,并且我可以通过mysql客户端
连接,并且可以访问数据库,但在代码中给出相同的密码时拒绝连接。



任何建议将不胜感激。
感谢,
劳拉

解决方案

实例ID 默认情况下包含项目ID。所以不要再显式添加项目标识。



项目ID: sampleapp



实例Id: sampleapp:instance1 (这是默认情况下创建的Google云数据库)

连接字符串:

正确:

   

正确

  JDBC:谷歌:MySQL的:// sampleapp:sampleapp:INSTANCE1 / DBNAME用户=根&安培;密码= +密码+ 了useUnicode =真安培;的characterEncoding = UTF-8\" ;? 


I have a google app engine connected project with which I am trying to connect to a google cloud sql database.I upload my project to google and via it I try to connect to the db.

my connection URL is as follows->

Class.forName("com.mysql.jdbc.GoogleDriver");
String password="";
    url = "jdbc:google:mysql://my-project-id:my-instance-name/dbname?user=root&password="+password+"useUnicode=true&characterEncoding=UTF-8";

    Connection conn = DriverManager.getConnection(url);

it is at the point where I attempt to get a connection with the url that I get an exception

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 then added the following string to my url-> &autoReconnect=true&failOverReadOnly=false&maxReconnects=10

then received a different exception-->

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 10 times. Giving up.

I have tried pinging the ip address of the db instance and it works fine.

Do I need to give any explicit permissions in my cloud sql instance for it to be able to connect?

Any suggestions are welcome.

The strange thing is that I am able to connect to the db using eclipse by going to project->google->app engine->usegoogle cloud sql instance->configure.I use the same user name (root) and password ("") here as in the url in the code but for some reason it refuses to connect through the code. I have also enabled the

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

tag in my appengine-web.xml

I changed the root password from "" to some value and I am able to connect via mysql client and I can access the database, but on giving the same password in code it refuses to connect.

Any suggestions will be appreciated. Thanks, Laura

解决方案

Instance Id by default contains the project Id. So don't explicitly add project Id again.

Project ID: sampleapp

Instance Id: sampleapp:instance1 (This is how google cloud sql creates by default)

Connections string:

Correct:

jdbc:google:mysql://sampleapp:instance1/dbname?user=root&password="+password+"useUnicode=true&characterEncoding=UTF-8";

In correct

jdbc:google:mysql://sampleapp:sampleapp:instance1/dbname?user=root&password="+password+"useUnicode=true&characterEncoding=UTF-8";

这篇关于com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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