I am trying to read a MySQL db record using this simple code in Google Apps Script:
function testConn(){
// make the connection
var connection = Jdbc.getConnection("jdbc:mysql://" + DB.URL + ":" + DB.PORT + "/" + DB.DATABASE, DB.USERNAME, DB.PASSWORD);
// perform the query
var SQLstatement = connection.createStatement();
var result = SQLstatement.executeQuery("SELECT date_available FROM oc_product where model = 'B23-U57-U57'");
var colNum = result.getMetaData().getColumnCount();
while(result.next()) {
var res = {};
for (var i=1; i<= colNum; i++) {
var label = result.getMetaData().getColumnLabel(i);
if (result.getMetaData().getColumnTypeName(i) == "DATE") {
var val = result.getDate(i);
} else {
var val = result.getString(i);
}
res[label] = (val);
}
Logger.log(JSON.stringify(res, null, 4));
}
}
Because the date_available
is "0000-00-00", this code throws error
Value '0000-00-00' can not be represented as
As suggested here I tried to use connection URL with parameter
?zeroDateTimeBehavior=convertToNull
But that also threw an error
The following connection properties are unsupported: zeroDateTimeBehavior.
What am I missing? Is this Google bug? Why this connection property is not supported? Is there any workaround apart of altering the SQL query?