简体   繁体   中英

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

在此处输入图像描述 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

在此处输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM