Member-only story

#002 Download {Type: Google Script}

Developers Group
2 min readApr 11, 2022

You can write data from Google Spreadsheet into MySQL database auto with just click of a button or scheduled time. This is great use for retrieving data in spreadsheet format.

Please find below script:

function myMySQLFetchData()
{
var conn = Jdbc.getConnection('jdbc:mysql://127.0.0.1:3306/employee_db', 'username', 'pass');

Replace the place holder credentials for MySQL, Also change MySQL query as per your MySQL database.

host : 127.0.0.1

database: employee_db

username: username

pass: password

var stmt = conn.createStatement();
var start = new Date();

Get script starting time

var rs = stmt.executeQuery('SELECT id,emp_name, emp_code FROM employee_details GROUP BY 1 LIMIT 1000');

It sets the limit of the maximum number of rows in a Result Set object

Change table name as per your database structure

var doc = SpreadsheetApp.getActiveSpreadsheet();

Returns the currently active spreadsheet, or you can hardcode this.

var cell = doc.getRange('a1');
var row = 0;
var getCount = rs.getMetaData().getColumnCount();

This code will count MySQL table column name.

for (var i = 0; i < getCount; i++)
{
cell.offset(row…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Developers Group
Developers Group

Written by Developers Group

A Developer is responsible for coding, designing, deploying, and debugging development projects, typically on the server-side (or back-end).

No responses yet

Write a response