Java 到云sql的连接失败错误

Java 到云sql的连接失败错误,java,google-cloud-endpoints,google-cloud-sql,Java,Google Cloud Endpoints,Google Cloud Sql,有时,我在连接云SQL时遇到通信失败错误。以下是错误详细信息: { "error": {"errors": [ { "domain": "global", "reason": "backendError", "message": "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the

有时,我在连接云SQL时遇到通信失败错误。以下是错误详细信息:

{ "error": {"errors": [   {
"domain": "global",    "reason": "backendError",
"message": "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."   }  ],  "code": 503,  "message": "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server." }}
请帮我做这个

我的java代码是:

 Class.forName ("com.mysql.jdbc.GoogleDriver");
con  = DriverManager.getConnection("<< connections , username,password>>");
java.sql.Statement stmt = con.createStatement();
String sqlpost = "<<  here is mysql query>>";
ResultSet rst = stmt.executeQuery(sqlpost);
int count = 0;
while (rst.next()) {
Users users = new Users(rst.getInt("id"), rst.getString("altername"));
friendlist.add(users);
}
con.close ();
Class.forName(“com.mysql.jdbc.GoogleDriver”);
con=DriverManager.getConnection(“>”);
java.sql.Statement stmt=con.createStatement();
字符串sqlpost=“>”;
结果集rst=stmt.executeQuery(sqlpost);
整数计数=0;
while(rst.next()){
Users Users=新用户(rst.getInt(“id”)、rst.getString(“altername”);
添加(用户);
}
con.close();

在运行查询之前,是否可以尝试使用新连接?连接空闲的时间可能足以导致该错误。我在一个函数中调用多个方法。每次,我都在方法中建立新连接并执行查询,然后响应来自方法的函数…我还可以做些什么来避免此错误?我试图在con.close()方法打开新连接之前关闭连接。它现在正在工作。同样,我有时也会遇到此问题…con.close()不是此错误的解决方案。请帮助我解决此问题。能否显示代码?能否在运行查询之前尝试使用新连接?连接空闲的时间可能足以导致该错误。我在一个函数中调用多个方法。每次,我都在方法中建立新连接并执行查询,然后响应来自方法的函数…我还可以做些什么来避免此错误?我试图在con.close()方法打开新连接之前关闭连接。它现在正在工作。同样,我有时也会遇到此问题…con.close()不是此错误的解决方案。请帮助我解决此问题。您能显示代码吗?