Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8758649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:36:10+00:00 2026-06-13T14:36:10+00:00

I am hoping someone can assist me in getting the JDBC script Reading from

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:36:11+00:00Added an answer on June 13, 2026 at 2:36 pm

    This script is supposed to run from a spreadsheet container or at least to have access to a spreadsheet to write its results.

    So you have 2 possibilities:

    1. Copy /paste your script in the spreadsheet script editor and run it from there.

    2. Replace the spreadsheetApp.getActive with openbyId(spreadsheet id)
      (See this other post for more information) your are indeed in almost the same situation since your script is not directly related to the spreadsheet it uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping someone can help me out here. I'm using Google Contacts API to fetch
I was hoping someone can assist in describing a workaround solution to the following
Hoping someone with a better knowledge of javascript can assist, I am wanting to
I'm hoping someone can help with this, I'm having a really difficult time getting
I'm hoping someone can help me. I've got a specific Exception from COM that
I have a bewildering problem, hoping someone can assist: I have a model object,
first question, hoping someone can help here. I've been trying to track down how
I'm hoping someone can assist me with understanding if/how something like this is possible.
I am hoping there is someone out there that can assist. I am very
Hoping someone can help me here as this is driving me insane. I used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.