1
votes

I'm having a lot of troubles to manage to have an online database for my Android app. I'll store some basic data of people with really basic relationships between tables. Also, I'll save some small photos but generally Strings and numbers.

I've downloaded and somehow understood the Google's "mobile backend starter": https://developers.google.com/cloud/samples/mbs/

But in that example they use Google Datastore as a database and I can't find an example on how to do it with Google Cloud SQL. Is there a possiblitity to communicate directly with the database from the Android App or do I have to create PHP webservices as if I would be using a regular MySQL database?

I know it's not going to be as easy as if I would be using SQLite, but I don't know where to start!

Thanks!

3

3 Answers

1
votes

Emiliosg, I ran into the same problem and after a LOT of search I ended up using raw JDBC connection to my Cloud SQL instance. It's working fine, even though I have been told it's not 'proper' to embed direct database communication in your app. Of course, no one can point me to a Cloud Endpoint example.

I don't have my code handy, but the steps are as follows:

  1. Load an register the standard JDBC driver.
  2. Create a connection using your instance IP\instance-name
  3. Process your SQL as usual.

I even ran stored procedures successfully, and I don't see the problem in communicating directly with your instance as long as you're using preparedStatement to avoid SQL injection, and you have set up a user account for your client app with minimal privileges.

You can use Toad to connect and manage your DB instance.

Let me know if you need code samples, but this is pretty standard java-DB interaction.

1
votes

I have done this before with Cloud Endpoints. I created a Cloud Endpoints API which had methods which then did operations on my Cloud SQL database.

This is much more secure than storing your Cloud SQL database connection credentials inside your Android app.

0
votes

Mobile Backend Starter does not support Cloud SQL. You can use Cloud SQL by extending and deploying the backend by yourself, but it's not as easy as using MBS with Datastore. I'd recommend you to try using Datastore at first.

Kaz