从另一个项目ID访问现有的Cloud SQL实例
我已经在PHP项目中创建了一个云sql实例,并成功完成了计费过程.该项目有效.
I have created a cloud sql instance in a PHP project and have made the billing procedure successfully. The project works.
现在,我想从另一个项目访问数据库,但是这次是在带有servlet的Java SDK项目中.使用 https://developers.google.com/appengine/中的示例docs/java/cloud-sql/
Now, I want to access my database from another project but this time in Java SDK project with servlets. Using the example in https://developers.google.com/appengine/ docs/java/cloud-sql/
在Java项目中,我有:
In Java project I have:
在php项目ID中,我有:项目编号:phptestID实例名称:phpinstanceName
In php project id I have: project id: phptestID instance name: phpinstanceName
在Servlet的代码中,我进行以下连接:
In my code in Servlet i do the below connection:
String url = "jdbc:google:mysql://phptestID:phpinstanceName/dbname?user=root";
Connection conn = (Connection) DriverManager.getConnection(url);
(... >>此时连接失败,并且无法访问数据库以进行以下查询)
(...>> The connection fails in this point and doesn't access the database to make the below query )
String sqlStmt = "SELECT * FROM sometable";
PreparedStatement stmt = conn.prepareStatement(sqlStmt);
ResultSetres = stmt.executeQuery(sqlStmt);
如何在另一个项目中访问我的数据库?有没有其他办法your-project-id:您的实例名称???
How can I access my database in another project?? Is there any other way except your-project-id:your-instance-name???
您将需要授予新的App Engine应用访问您的CloudSQL实例的权限.为此,请转到控制台中的Cloud SQL实例,对其进行编辑,然后转到授权的App Engine应用程序,然后添加新的App Engine应用程序的应用程序ID.
You will need to give the new app engine app access to your CloudSQL instance. To do this go to the Cloud SQL instance in the console, edit it, go down to Authorized App Engine Applications and then add the app id of the new App Engine app.
更新:
最近的步骤如下面的附件屏幕快照中所示
The most recent steps look like in the attached screenshot below