我只是在学习使用 Google 表格脚本,并尝试登录我的 MySQL 数据库,下面是我的代码
function readData() {
var conn = Jdbc.getConnection('jdbc:mysql://hostname(or using IP Address):3306/database_name',username,password);
var stmt = conn.createStatement();
var results = stmt.executeQuery('SELECT * FROM tablename');
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Sheet1');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
results.close();
stmt.close();
sheet.autoResizeColumns(1, numCols+1);
}
而且我已经从 cPanel-Databases-Remote MySQL 获得了额外的 MySQL 访问主机 (WHM)
64.18.0-15.%
64.233.160-191.%
66.102.0-15.%
66.249.80-95.%
72.14.192-255.%
74.125.%
173.194.%
207.126.144-159.%
209.85.128-255.%
216.239.32-63.%
所以我尝试运行它,但我收到错误消息
异常:无法建立数据库连接。检查连接字符串、用户名和密码。(第 9 行,文件“代码”)
是否有任何遗漏或尚未设置?请帮我解决这个问题?