Purushothaman U
Purushothaman U

Reputation: 69

How to connect to mysql or postgresql database running on a cloud server with appscripts?

I am trying to connect to a postgresql server, which is currently running on a google cloud machine with appscripts. I want to push the data from the google spreadsheet to that postgresql database, I have tried to achieve this with the help of jdbc documentation provided in this documentation. I have gone through the documentation but couldn't find anything related to postgresql, so i tried connecting with mysql database running on the same server but it is showing the error

enter image description here The code which I tried for connecting to mysql looks like

var server = 'ipaddress'
var dbName = 'dbname'
var username = 'db name'
var password = 'password'
var port = 3306
var url = 'jdbc:mysql://' + server + ":" + port + "/" + dbName;
function myFunction() {
  var conn = Jdbc.getConnection(url, username, password)
  Logger.log(url);
  Logger.log(conn);
  conn.close();
}

My current code for postgresql looks like

var dbName = 'dbname'
var username = 'username'
var password = 'password'
var port = 5432
function myFunction() {
  var url = 'jdbc:postgresql://' + server + ":" + port + "/" + dbName;
  var conn = Jdbc.getConnection(url, username, password)
  Logger.log(url);
  Logger.log(conn);
  conn.close();
}

I am getting the error

enter image description here

How to solve this? and is it even possible to connect to postgresql with appscripts? PS I am able to connect to the same database with same credentials with pgadmin

Upvotes: 1

Views: 3978

Answers (1)

alramdein
alramdein

Reputation: 901

From Apps Script documentation here :

The JDBC service supports Google Cloud SQL MySQL, MySQL, Microsoft SQL Server, and Oracle databases.

So PostgreSQL is not yet supported.

For the MySQL connection, from the error message, it is clear that your credentials seems wrong. Check it by login to your database remote server via terminal

mysql -u <username> -p -h <ip_address>

or connect it via Database Tools like DBeaver

Upvotes: 1

Related Questions