Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

java - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...