如何解决这个异常?我无法通过应用引擎插件访问云上的数据库。
我正在使用appengine 1.9.22
这是我的打印堆栈:朱恩,2016年下午7:41:30
com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver openConnection
AVERTISSEMENT: openConnection
java.sql.SQLException: 404 OK
Not Found
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.newOpenConnectionIOException(RpcGoogleApi.java:168)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:102)
at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver.openConnection(LocalRdbmsServiceRemoteDriver.java:206)
at com.google.appengine.api.rdbms.dev.LocalRdbmsService.openConnection(LocalRdbmsService.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:521)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:475)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:452)
at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:493)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:490)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.google.api.client.http.HttpResponseException: 404 OK
Not Found
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1061)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.execImpl(RpcGoogleApi.java:326)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.exec(RpcGoogleApi.java:308)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:99)
... 16 more
发布于 2017-03-18 04:35:55
当我在本地运行时,我使用第二代云sql连接到我的db :)
发布于 2016-06-13 08:13:35
上星期五我也遇到了同样的问题。
我没有找到任何支持这种说法的文档,但是,通过阅读关于如何用java连接到云sql的当前google文档和指南,似乎不推荐rdbms.dev.LocalRdbmsServiceRemoteDriver。
我建议您升级代码,以便在生产中使用com.mysql.jdbc.GoogleDriver,在开发中使用MySQL连接器/J。
在开发中,您可以使用您自己的mysql数据库,运行在本地主机上或远程运行。如果想使用Google中的数据库,可以将Cloud的实例配置为来自网络的允许外部访问,然后像任何其他mysql服务器一样创建一个连接。
您可以为每个运行时环境创建一个db连接:
protected Connection getConnection() throws SQLException{
Connection c = null;
String url = null;
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
try {
Class.forName("com.mysql.jdbc.GoogleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Driver unavailable.");
}
url = System.getProperty("ae-cloudsql.cloudsql-database-url.prod");
}else{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
System.out.println("Driver unavailable.");
}
url = System.getProperty("ae-cloudsql.cloudsql-database-url.dev");
}
c = DriverManager.getConnection(url);
c.setAutoCommit(false);
return c;
}
从文件中摘录:
-使用
https://stackoverflow.com/questions/37766820
复制相似问题