为Jdbc.getConnection设置高级参数 [英] setting advanced parameters for Jdbc.getConnection

查看:152
本文介绍了为Jdbc.getConnection设置高级参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Google Apps脚本安全地连接到 SQL Google Cloud Platform .但是,我不确定如何设置Jdbc.getConnection方法的参数_serverSslCertificate, _clientSslCertificateclientSslKey.我已经下载了证书和密钥文件.

I'd like to connect securely to SQL Google Cloud Platform using Google Apps Script. However, I'm not sure how to set the parameters _serverSslCertificate, _clientSslCertificate, and clientSslKey of Jdbc.getConnection method. I already downloaded cert and key files.

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAlj6vYtt6F8rv254sllmvGogSYwzS0JaB6Yezji6Ab+gmZPLc
dyfNIg4PTe8YCz45RnJ+8VVklTQ4K/MFzsB6nilNMDSFRCAfRmytQkioEFlgzdL+
...
JOyb/68aCqHHStwlpCUTH40Iqh3kneiQ1be2XigxjllMSYkuH/ebZw==
-----END RSA PRIVATE KEY-----

如何为_serverSslCertificate分配字符串文字?例如...

How should I assign a string literal to _serverSslCertificate? For example...

var serverSslCert = '-----BEGIN RSA PRIVATE KEY-----\n\
MIIEpAIBAAKCAQEAlj6vYtt6F8rv254sllmvGogSYwzS0JaB6Yezji6Ab+gmZPLc\n\
dyfNIg4PTe8YCz45RnJ+8VVklTQ4K/MFzsB6nilNMDSFRCAfRmytQkioEFlgzdL+\n\
...
JOyb/68aCqHHStwlpCUTH40Iqh3kneiQ1be2XigxjllMSYkuH/ebZw==\n\
-----END RSA PRIVATE KEY-----';

推荐答案

证书在getConnection(url,info)的info参数中发送. https://developers.google.com/apps-script/reference /jdbc/jdbc#getconnectionurl-info

The certs are send in the info parameter of getConnection(url,info). https://developers.google.com/apps-script/reference/jdbc/jdbc#getconnectionurl-info

示例:

var serverSslCert = PropertiesService.getScriptProperties().getProperty("serverSslCert");

 var sqlInfo = {_serverSslCertificate: serverSslCert,
                _clientSslCertificate:"...",
                _clientSslKey:"..."
               };

 var conn = Jdbc.getConnection('jdbc:mysql://yoursqlserver.example.com:3306/database_name',
                                sqlInfo);

尽管JDBC服务中有一些Google Cloud SQL特定的连接方法.

There are some Google Cloud SQL specific connection methods in the JDBC service though.

https://developers.google.com/apps-脚本/参考/jdbc/jdbc#getcloudsqlconnectionurl-info

https://developers.google.com/apps-script/reference/jdbc/jdbc#getconnectionurl-username-password

这篇关于为Jdbc.getConnection设置高级参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆