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:
In php project id I have: project id: phptestID instance name: phpinstanceName
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???
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With