Accessing existing cloud SQL instance from another project ID
Asked Answered
E

1

5

I have created a cloud sql instance in a PHP project and have made the billing procedure successfully. The project works.

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/

In Java project I have:

project id: javaProjectID

In php project id I have: project id: phptestID instance name: phpinstanceName

database: dbname

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);

How can I access my database in another project?? Is there any other way except your-project-id:your-instance-name???

Economical answered 7/5, 2014 at 13:10 Comment(2)
You query is confusing. What do you mean by mean another project here. You can access add access control to any number of applications for your CLoud SQL instance.Varicella
Also copy the mysql-connector-java jar in the location of your machine where the appengine SDK is installed. *SDK LOCATION \appengine-java-sdk-1.8.9\lib\impl*Varicella
M
14

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.

UPDATE:

The most recent steps look like in the attached screenshot below screenshot

Measly answered 7/5, 2014 at 15:35 Comment(3)
IanGSY, it's still a valid solution? Because I'm not able to find the Authorized App Engine Applications in my SQL instance consoleAphid
@Luciano... It is still valid. App Engine Authorization can be found in "Connections" menu item of SQL Instance and then expand link "Authorize apps in other projects" .Loram
How does this work for cross project connections? This only works for instances in the same project?Spermatic

© 2022 - 2024 — McMap. All rights reserved.