I am hoping someone can assist me in getting the JDBC script Reading from a Database example here... https://developers.google.com/apps-script/jdbc ...to work with my db.
function foo() {
var conn = Jdbc.getConnection("jdbc:mysql://<host>:3306/<instance>", "user", "password");
var stmt = conn.createStatement();
stmt.setMaxRows(100);
var start = new Date();
var rs = stmt.executeQuery("select * from clients");
var doc = SpreadsheetApp.getActiveSpreadsheet();
var cell = doc.getRange('a1');
var row = 0;
while(rs.next()) {
cell.offset(row, 0).setValue(rs.getString(1));
cell.offset(row, 1).setValue(rs.getString(2));
cell.offset(row, 2).setValue(rs.getString(3));
cell.offset(row, 3).setValue(rs.getString(4));
row++;
}
rs.close();
stmt.close();
conn.close();
var end = new Date();
Logger.log("time took: " + (end.getTime() - start.getTime()));
}
I plugged in my server and user info and changed the select * statement to the table "clients" in my db. Connection is successful but I get the following error...
TypeError: Cannot call method "getRange" of null. (line 9)
The table "clients" in my db has the following columns...
id, clientname, clientcontact, clientphone, clientnote
Can someone help me understand what needs to be changed in the example script for it to work with my clients table? I am not a programmer by far... but I would like to get this working and use it as a template to get data from mysql into google spreadsheets so I can then publish the sheet on my google site.
Thanks!