GAE和本地MysqlServer问题:访问被拒绝(“java.lang.RuntimePermission”“modifyThreadGroup”)

时间:2017-02-11 01:49:02

标签: java android mysql google-app-engine

我已经尝试过一个解决方案,我已经做了几个程序来解决这个问题,但没有成功。我最后的希望是这个话题......

我正在运行一个本地Mysql服务器,我在Android Studio中使用Google App Engine。我的后端无法与我的本地数据库通信。我在GAE上部署时在Google和SQL中创建了一个SQL数据库,使用谷歌数据库工作正常。问题仅发生在本地环境中。

我的代码:

public Connection getConnection() throws SQLException {

        String url = null;

    try {
        if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
            // Load the class that provides the new "jdbc:google:mysql://" prefix.
            Class.forName("com.mysql.jdbc.GoogleDriver");
            url = "jdbc:google:mysql://XXXXXt:us-central1:YYYYYY/Project?user=root&password=xxxxx";
        } else {
            // Local MySQL instance to use during development.

            Class.forName("com.mysql.jdbc.Driver");
            url = "jdbc:mysql://127.0.0.1:3306/Project?user=root&password=xxxxx";

            // Alternatively, connect to a Google Cloud SQL instance using:
            // jdbc:mysql://ip-address-of-google-cloud-sql-instance:3306/guestbook?user=root
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    return DriverManager.getConnection(url);
}

摇篮:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.34'
    }
}

repositories {
    mavenCentral()
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.49'
    compile 'com.google.appengine:appengine-endpoints:1.9.34'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.34'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.google.apis:google-api-services-sqladmin:v1beta4-rev37-1.22.0'
    compile 'com.google.cloud.sql:mysql-socket-factory:1.0.2'
    compile 'mysql:mysql-connector-java:5.1.40'
}

appengine {
    downloadSdk = true
    httpAddress = "0.0.0.0"
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

应用-引擎:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>myApplicationId</application>
    <version>1</version>
    <threadsafe>true</threadsafe>

    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
    </system-properties>
    <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

有什么建议吗?

0 个答案:

没有答案