Search code examples
mysqlvariablesjdbcoutput

Javascript output sql query result to variable mysql


I used Oracle a few years ago and remember thet i used a product of them (OO4O). With this it was possible to output the sqlquery result to a variable, using it in user defined function (Excel). My question is: can we achive this using Google Appscript and a MYSql database? Many thanks for any help, Octávio

Final goal would be the store the result of a sql statement like 'SELECT SUM(database.table_field) INTO (the variable i mentioned....") I searched but found no documentation about this


Solution

  • Sorry for the confusion. In the meantime I managed to get the solution and never tought it could be so simple as: Thank you. Octávio.

        function somareg(){ var url = 'jdbc:mysql://'+server+':'+port+'/'+dbName; var conn = Jdbc.getConnection(url, username, password); const stmt = conn.createStatement(); const guarda = stmt.executeQuery("SELECT SUM(valor) FROM registos"); guarda.next(); Logger.log(guarda.getDouble(1)); //This is what I was looking for... }