无法在Google应用脚本中连接Postgres数据库

时间:2017-07-21 07:42:27

标签: javascript postgresql jdbc google-apps-script

我尝试使用他们的Jdbc连接器在谷歌应用脚​​本中连接Postgres数据库。但它没有连接。获取此异常连接URL使用不受支持的JDBC协议。

以下是使用的代码:

var address = <db_address>;
var user = <user_name>;
var userPwd = <password>;
var db = <db_name>;

var dbUrl = 'jdbc:postgresql://' + address + '/' + db;

// Read up to 1000 rows of data from the table and log them.
function readFromTable() {
  try{
  var conn = Jdbc.getConnection(dbUrl, user, userPwd);

  var start = new Date();
  var stmt = conn.createStatement();
  stmt.setMaxRows(1000);
  var results = stmt.executeQuery('SELECT * FROM coins');
  var numCols = results.getMetaData().getColumnCount();

  while (results.next()) {
    var rowString = '';
    for (var col = 0; col < numCols; col++) {
      rowString += results.getString(col + 1) + '\t';
    }
    Logger.log(rowString)
  }

  results.close();
  stmt.close();

  var end = new Date();
  Logger.log('Time elapsed: %sms', end - start);
  }catch (err) {
    Logger.log(err.message);
  }
}

0 个答案:

没有答案