Juzer
Juzer

Reputation: 35

How to connect to google cloud sql instance from eclipse using App Engine?

I am trying to connect to google cloud sql instance from eclipse in my app engine connected android project. So far i am able to connect to cloud sql instance using Class.forname("com.mysql.jdbc.Driver"). But it requires authorising my ip address in google cloud sql every time i want to use the instance hence making it unfeasible. I know that while connecting from app engine i dont need to authorize my ip address. Bur for that i have to use GoogleDriver ie. Class.forname("com.mysql.jdbc.GoogleDriver"). But when i run my code it gives me ClassNotFoundException.

I am stuck at this situation for a long time. Please give me a proper solution to the problem

Upvotes: 1

Views: 1125

Answers (2)

Juzer
Juzer

Reputation: 35

I have authorised 0.0.0.0/0 in access control in my cloud instance and now all the devices are able to connect to the cloud instance with stock mysql driver ie. com.mysql.jdbc.Driver without need to changing authorised network again and again in access control.

Still can't figure out to implement GoogleDriver but for now this solution will work. If anyone find a more better and general way to connect to cloud instance please post your answer.

Upvotes: 0

David
David

Reputation: 9721

The GoogleDriver is only intended to be used when actually running on App Engine. When running from eclipse or the dev_appserver you will have to use the stock com.mysql.jdbc.Driver class, and you will have to authorize your IP address. A good example of this is shown in the documentation, which demonstrates how to choose in code which driver to use. Note the commented out line for connecting from your dev environment to Cloud SQL.

As an FYI don't forget to enable the connector for running on App Engine.

Upvotes: 1

Related Questions