3

I am trying to pull data from a MySql database into a Google Doc via Apps Script. When I try connect to the database I get the error below because Jdbc is undefined.

Cannot read property 'getConnection' of undefined 

Below is the code I am using

<div>
  <span id="import" style="background-color: red">Import</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
  /**
   * On document load, assign click handlers to each button and try to load the
   * user's origin and destination language preferences if previously set.
   */
  $(function() {
    $('#import').click(import_test); 
  });


// Replace the variables in this block with real values.
var address = 'ip';
var user = 'username';
var userPwd = 'password';
var db = 'db';

var dbUrl = 'jdbc:mysql://' + address + '/' + db;

// Read up to 1000 rows of data from the table and log them.
function readFromTable() {
  var conn = Jdbc.getConnection(dbUrl, user, userPwd);
}

function import_test() {
console.log('ping');
readFromTable();
console.log('ping2');
}

</script>

The documentation is only for Google Cloud SQL and I can't find anything in the mysql documentation on how to do this in javascript.

Any ideas on how to connect to MySql via Apps Script?

Thanks.

1 Answer 1

1

As with most frameworks, all database calls should be done from the server, not the browser.

Put it on the server and call a server function from the client js.

Sign up to request clarification or add additional context in comments.

2 Comments

From my understand you should be able to connect to the database from AppsScript. If you check out the documentation they seem to do it there pretty easily. developers.google.com/apps-script/guides/…
I see my problem now (your words made me think!). My code connecting to the database was not in the Google Apps Script, but was in my javascript. Silly thinking it should work. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.