Google Apps Script error when trying to read into a database using jdbc
I have a google apps script that is working in one instance, but not another
Both scripts are identical, the only difference I have programmed is the
jdbc query.
Here is the working function:
function wbk() {
var conn = Jdbc.getConnection("jdbc:mysql://aaa.aaaa.org:3306/aaaaa",
"aaaa", "bbbbb");
var stmt = conn.createStatement();
stmt.setMaxRows(10000);
var start = new Date();
var rs = stmt.executeQuery("SELECT `DateUpdate`, `AllianceName`,
`PlayerName`, `Score`, `Rank`, `TotalCities`, `FameTotal`, `FameRank`,
`DefeatedTotal`, `DefeatedRank`, `PlunderTotal`, `PlunderRank` FROM
`Member` WHERE AllianceID='2' OR AllianceID='48'");
var doc = SpreadsheetApp.getActiveSpreadsheet();
var first = doc.getSheetByName("WBK");
first.activate();
var cell = first.getRange('b2');
var row = 0;
while (rs.next()) {
for (var col = 0; col < rs.getMetaData().getColumnCount(); col++) {
cell.offset(row, col).setValue(rs.getString(col + 1));
}
row++;
}
rs.close();
stmt.close();
conn.close();
var end = new Date();
Logger.log("time took: " + (end.getTime() - start.getTime()));
};
I ran this twice, after updating the db and the results were perfect, just
what was expected.
Now, when I try to use the same function, and only modify the query (and I
checked the SQL statement in the db, that's just fine), the function
fails.
Here is the non working function.
function WC_Combined() {
var conn = Jdbc.getConnection("jdbc:mysql://aaa.aaaa.org:3306/aaaaa",
"aaaa", "bbbbb");
var stmt = conn.createStatement();
stmt.setMaxRows(10000);
var start = new Date();
var rs = stmt.executeQuery("SELECT `DateUpdate`, `AllianceName`,
`PlayerName`, `Score`, `Rank`, `TotalCities`, `FameTotal`, `FameRank`,
`DefeatedTotal`, `DefeatedRank`, `PlunderTotal`, `PlunderRank` FROM
`Member` where AllianceID='195' OR AllianceID='494'");
var doc = SpreadsheetApp.getActiveSpreadsheet();
var first = doc.getSheetByName("Combined");
first.activate();
var cell = first.getRange('b2');
var row = 0;
while (rs.next()) {
for (var col = 0; col < rs.getMetaData().getColumnCount(); col++) {
cell.offset(row, col).setValue(rs.getString(col + 1));
}
row++;
}
rs.close();
stmt.close();
conn.close();
var end = new Date();
Logger.log("time took: " + (end.getTime() - start.getTime()));
};
The error message I get in the debug console on Google is
Service error: Spreadsheets (line 110, file "Code")
Line 110 in my code is cell.offset(row, col).setValue(rs.getString(col +
1)); in the second function I have provided above; I cannot find any
difference between this line in the 2nd function or the 1st example I have
provided ---- and they both worked the first time I tried to run them.
Any ideas, anyone? I haven't even used custom code, the code is basically
the google apps documentation example.
I am using Google scripting within a Google Docs Spreadsheet, connecting
to mysql. I've opened up the remote connections to mysql, and have 2
working spreadsheets, so I know the connection works.
No comments:
Post a Comment