Connect to mysql via JDBC in JavaScript - Stack Overflow

I am trying to pull data from a MySql database into a Google Doc via Apps Script. When I try connect to

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/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.

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./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.

Share Improve this question asked Jun 26, 2014 at 9:33 Ryan-Neal MesRyan-Neal Mes 6,26310 gold badges54 silver badges80 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966239a4603696.html

相关推荐

  • Connect to mysql via JDBC in JavaScript - Stack Overflow

    I am trying to pull data from a MySql database into a Google Doc via Apps Script. When I try connect to

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信