我尝试使用他们的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);
}
}