-2
我有一個Microsoft Azure SQL數據庫,我想將我的Google App腳本連接到查看或更改數據。到目前爲止,我已經成功地在頁面腳本中使用JDBC連接,但是當我在一個站點腳本上運行相同的腳本時,我遇到了一個問題。我已經嘗試將它寫入'Code.gs'文件,然後用'google.script.run'在我的HTML文件中調用它。我試過把它作爲一個JavaScript函數寫在HTML文件本身,但仍然沒有bueno。似乎有一個缺失的圖書館或引用不在網站中的圖表。有任何想法嗎?下面是審查代碼:Google協作平臺 - JDBC到Azure SQL DB
// Gets data from the external database
// Same function used in both sheets and sites
function getStores() {
conn = Jdbc.getConnection("jdbc:sqlserver://azureDB.database.windows.net:1433;databaseName=dbName",
"userName", "password");
var stmt = conn.createStatement();
var result = stmt.executeQuery("select something from somethingElse");
var resArray = result.getArray(1);
return resArray;
}
// Loads the collected data into the <option> elements of a <select> element
// Currently throws 'Uncaught ReferenceError: Jdbc is not defined' in Chrome Console
function loadStores() {
var resArray = getStores();
var eleSelectElement = document.getElementById('SelectElement');
var i;
for (i = 0; i < retArray.length; i++)
{
var option = document.createElement('option');
option.text = 'Value: ' + resArray [i];
option.value = resArray [i];
eleSelectElement.add(option);
}
}
// Loads the collected data into the first column of the spreadsheet
// Works as expected
function loadSheet() {
var resArray = getStores();
var doc = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/UID/edit');
var cell = doc.getRange('a1');
for (var i = 0; i < resArray.length; i++)
cell.offset(i,0).setValue(resArray[i]);
}