访问被拒绝(“java.lang.RuntimePermission”“modifyThreadGroup”)

时间:2014-08-18 14:32:36

标签: google-app-engine google-cloud-sql

我正在使用Google Appengine和Goodle Cloud SQL开发服务器应用程序。在本地计算机上运行服务器时尝试连接到云SQL时遇到问题。我收到错误:

  

java.security.AccessControlException:访问被拒绝   (“java.lang.RuntimePermission”“modifyThreadGroup”)

这是servlet代码:

package com.example.example;

import com.google.appengine.api.utils.SystemProperty;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.http.*;

public class MyServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Please use the form to POST to this url");
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        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://app_id:instance_id/data?user=root";
            } else {
                // Local MySQL instance to use during development.
                Class.forName("com.mysql.jdbc.Driver");
                url = "jdbc:mysql://instance-ip:3306/data?user=root";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        PrintWriter out = resp.getWriter();
        try {
            Connection conn = DriverManager.getConnection(url);
            System.out.println("Connection established");
            out.println("Connection established");
            try {
            } finally {
                conn.close();
            }
        } catch (SQLException e) {
            out.append(e.getMessage());
            e.printStackTrace();
        }
    }

}

我已将以下行添加到java.policy文件中:

  

权限java.lang.RuntimePermission“modifyThreadGroup”;

但这并没有解决问题。

0 个答案:

没有答案