我得到了这个异常java.sql.SQLException:404 OK我在本地运行我的appengine应用程序

时间:2016-06-11 17:47:38

标签: java google-app-engine

enter image description here

如何修复此异常我无法通过app引擎插件访问云端谷歌数据库

我正在使用appengine 1.9.22

这是我的打印堆栈: 2016年7月11日下午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

2 个答案:

答案 0 :(得分:0)

上周五我遇到了同样的问题。

我没有找到任何支持此声明的文档,但是,通过阅读current google's documentation and guides on how to connect to cloud sql with java,似乎不推荐使用rdbms.dev.LocalRdbmsServiceRemoteDriver。

我建议您升级代码,以便在生产中使用com.mysql.jdbc.GoogleDriver,在开发中使用MySQL Connector / J.

在开发中,您可以使用在localhost或远程运行的自己的mysql数据库。如果您想使用来自Google Cloud SQL的数据库,您可以从您的网络将您的云SQL实例配置为allow external access,然后像任何其他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;
    }

从文档中摘录:

- Creating a New Web App with Cloud SQL Support

- Using Google Cloud SQL

答案 1 :(得分:0)

当我在本地运行时,我正在使用第二代云sql连接到我的数据库:)