0

I am new to this JDBC driver. I am looking for ways to save user data from my android app to the google cloud mySQL. I happen to come across that JDBC might get this done.

However, I encounter this error No suitable driver found for jdbc:mysql://google/waveUserData?cloudSqlInstance=wavdata&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false

I have already downloaded the JDBC driver and put inside /library/java/extensions

Please help me with this, or please recommend me a method to efficiently user data from app to Google cloud mysql.

This is the code I am referring to: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/blob/master/examples/compute-engine/src/main/java/com/google/cloud/sql/mysql/example/ListTables.java

package com.google.cloud.sql.mysql.example;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* A sample app that connects to a Cloud SQL instance and lists all       available tables in a database.
*/
public class ListTables {
  public static void main(String[] args) throws IOException,   SQLException {
    // TODO: fill this in
   // The instance connection name can be obtained from the instance overview page in Cloud Console
// or by running "gcloud sql instances describe <instance> | grep connectionName".
String instanceConnectionName = "<insert_connection_name>";

// TODO: fill this in
// The database from which to list tables.
String databaseName = "mysql";

String username = "root";

// TODO: fill this in
// This is the password that was set via the Cloud Console or empty if never set
// (not recommended).
String password = "<insert_password>";

if (instanceConnectionName.equals("<insert_connection_name>")) {
  System.err.println("Please update the sample to specify the instance connection name.");
  System.exit(1);
}

if (password.equals("<insert_password>")) {
  System.err.println("Please update the sample to specify the mysql password.");
  System.exit(1);
}

//[START doc-example]
String jdbcUrl = String.format(
    "jdbc:mysql://google/%s?cloudSqlInstance=%s"
        + "&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false",
    databaseName,
    instanceConnectionName);

Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
   //[END doc-example]

try (Statement statement = connection.createStatement()) {
  ResultSet resultSet = statement.executeQuery("SHOW TABLES");
  while (resultSet.next()) {
    System.out.println(resultSet.getString(1));
      }
    }
  }
}
bunbun
  • 2,595
  • 3
  • 34
  • 52
jetjetboi
  • 142
  • 1
  • 14
  • You are linking to a project for server to server communication. If you are trying to use JDBC within your Android app please read [JDBC vs Web Service for Android](https://stackoverflow.com/q/15853367/295004) – Morrison Chang Dec 17 '18 at 04:15
  • Thanks for your comment. I am abit lost. Could you briefly explain how can I do it with web service to connect android studio with google cloud mySQL? – jetjetboi Dec 17 '18 at 13:23
  • @MorrisonChang how about using google cloud function or firebase cloud function to retrieve and store data to and from gcloud mySQL? – jetjetboi Dec 17 '18 at 13:24

0 Answers0