1
votes

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

2
We'd need some code or something to be able to help you. My theory is that if this happens when you deploy your project, then maybe your "com.mysql.jdbc.GoogleDriver" isn't properly packaged with your App?. where in your project structure is that class?Patrice
Actually i am putting this code in MainActivity under an Async Task: but somehow i feel that this is not the proper place to place this code:... Class.forName("com.mysql.jdbc.GoogleDriver");Juzer
Also I don't see GoogleDriver Class in mysql-connector-java-5.1.34-bin.jar ...only Driver class is available...Juzer
so this could very well be your issue. Find where the class is on your PC, and make sure you add it to your packaging as you deploy?Patrice
is com.mysql.jdbc.GoogleDriver class same as com.mysql.jdbc.Driver ...also i need to make sure that i have to put this code : "Class.forname("com.mysql.jdbc.GoogleDriver")" in the MainActivity of my client application or somewhere into the generated AppEngine Application?...Juzer

2 Answers

1
votes

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.

0
votes

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.