In google app script, I use getstring() to retrieve the data from mysql to write the result into array, like the example by google help file. However, my table has 100,000 rows and 20 columns. It takes more than 10 mins to convert to an array. In the JDBC class, there is getarray(). I cannot find any example of how to use getarray to convert the JDBCResultSet To array. Here is the help in google https://developers.google.com/apps-script/reference/jdbc/jdbc-array#getArray() and https://developers.google.com/apps-script/guides/jdbc#read_from_the_database Can anyone help? Does the getarray() convert faster than getstring()? I have already found this post. But there is no answer yet. How to getArray from JdbcResultSet in google app script?
here is my code:
function temp1() {
var conn = Jdbc.getConnection('jdbc:mysql://' + connectionName + '/' + db, user, userPwd)
var stmt= conn.createStatement();
var results = stmt.executeQuery('select * from abctable')
myarray = []
var myarray = results.getArray(1)
Logger.log(myarray)
}
If I use google recommended method, and I just get one column with 100,000 rows, the following code takes about 4 minutes to convert the JdbcResultSet to an array to reach to the Logger.log row:
function temp2() {
var conn = Jdbc.getConnection('jdbc:mysql://' + connectionName + '/' + db, user, userPwd)
var stmt= conn.createStatement();
var results = stmt.executeQuery('select first-column from abctable')
myarray = []
while (results.next()) {
myarray.push(["'" + results.getString(1)])
}
Logger.log(myarray)
}
Help help please.