java - How to connect to cloud SQL from android studio? -


i want connect cloud sql android studio. below code using make connection. require proxy settings cloud console? need install sql on pc or similar?

also, far have written code below , getting, no suitable driver found, error.

code:

    public void getdatafromsql() {     log.d("geol", "getsql");     connection connection;     string query = "some query";     try {         string databasename = "databasename";          string instanceconnectionname = "instanceconnectionname";          string jdbcurl = string.format(                 "jdbc:mysql://google/%s?cloudsqlinstance=%s&"                         + "socketfactory=com.google.cloud.sql.mysql.socketfactory",                 databasename,                 instanceconnectionname);         connection = drivermanager.getconnection(jdbcurl, user, password);         statement statement = connection.createstatement();         resultset resultset = statement.executequery(query);         log.d("geol", string.valueof(resultset));     } catch (sqlexception e) {         e.printstacktrace();     } } 

error message:

07-28 16:55:22.881 11550-11550/com.example.pratyush.geofencing w/system.err: java.sql.sqlexception: no suitable driver found jdbc:mysql://google/[databasename]?cloudsqlinstance=[instancename]&socketfactory=com.google.cloud.sql.mysql.socketfactory 07-28 16:55:22.886 11550-11550/com.example.pratyush.geofencing w/system.err:     @ java.sql.drivermanager.getconnection(drivermanager.java:594) 07-28 16:55:22.886 11550-11550/com.example.pratyush.geofencing w/system.err:     @ java.sql.drivermanager.getconnection(drivermanager.java:219) 07-28 16:55:22.886 11550-11550/com.example.pratyush.geofencing w/system.err:     @ com.example.pratyush.geofencing.main2activity.getdatafromsql(main2activity.java:169) 07-28 16:55:22.886 11550-11550/com.example.pratyush.geofencing w/system.err:     @ com.example.pratyush.geofencing.main2activity$1.onclick(main2activity.java:62) 

so if want connect external mysql database via jdbc have import corresponding jdbc driver.

please have @ following link: https://gist.github.com/cofearabi/5039135

this example android. driver can downloaded official mysql homepage

https://dev.mysql.com/downloads/connector/j/


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -