M
M
Mirtopir2020-03-02 11:27:40
Google Apps Script
Mirtopir, 2020-03-02 11:27:40

Google Apps Script Jdbc.getConnection how to connect to MySQL?

Good afternoon, I need advice from a practitioner who really has a connection string.

function Test(){
  var connectionName = 'remotemysql.com';
  var user = 'xaqfnhqzgE';
  var userPwd = 'o8uJU5UeIH';
  var db = 'xaqfnhqzgE';
  var dbUrl = 'jdbc:mysql://'+connectionName+'/'+db;
  var conn = Jdbc.getConnection(dbUrl, user, userPwd); 
  //var conn = Jdbc.getConnection('jdbc:mysql://37.59.55.185:3306/xaqfnhqzgE','xaqfnhqzgE','o8uJU5UeIH');
  conn.close(); 
}

I get
an Exception: Failed to connect to the database. Check the connection string and username and password.
With the same data I successfully connect via heidisql.
Also tried to connect to DB from https://www.db4free.net/
Same problem.
I read about whitelists for IP from Google.
https://developers.google.com/apps-script/guides/j...
There are doubts that both providers sent all Google ips to the ban, but I can’t influence this matter in any way?
Installed MySQL on my computer, same error. Disabling the firewall completely didn't help.
In general, there are 1000 Jdbc.getConnection connection strings in the vastness of the network. Everything works for everyone, but I don’t (
Where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2020-03-02
@Mirtopir

Classic version

var conn = Jdbc.getConnection(
  'jdbc:mysql://sql4.freemysqlhosting.net:3306/sql427628?useUnicode=true&characterEncoding=UTF-8',
  'sql427628', '****');
var stmt = conn.createStatement();
stmt.setMaxRows(1000);
var start = new Date();
var rs = stmt.executeQuery('select * from person');

var row = 0;
while (rs.next())
  for (var col = 0; col < rs.getMetaData().getColumnCount(); col++)
    console.log(rs.getString(col + 1));
rs.close();
stmt.close();
conn.close();

As far as I remember, https://www.db4free.net has some peculiarity in terms of the database name - it is not in the root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question