【问题标题】:Connect to mysql via JDBC in JavaScript在 JavaScript 中通过 JDBC 连接到 mysql
【发布时间】:2014-08-17 02:23:20
【问题描述】:

我正在尝试通过 Apps 脚本将数据从 MySql 数据库中提取到 Google Doc 中。当我尝试连接到数据库时,我收到以下错误,因为 Jdbc 未定义。

Cannot read property 'getConnection' of undefined 

下面是我正在使用的代码

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

该文档仅适用于 Google Cloud SQL,我在 mysql 文档中找不到有关如何在 javascript 中执行此操作的任何内容。

关于如何通过 Apps 脚本连接到 MySql 的任何想法?

谢谢。

【问题讨论】:

    标签: javascript mysql jdbc google-apps-script


    【解决方案1】:

    与大多数框架一样,所有数据库调用都应该从服务器而不是浏览器完成。

    放在服务端,从客户端js调用一个服务端函数。

    【讨论】:

    • 据我了解,您应该能够从 AppsScript 连接到数据库。如果您查看文档,他们似乎很容易在那里完成。 developers.google.com/apps-script/guides/…
    • 我现在看到了我的问题(你的话让我思考!)。我连接到数据库的代码不在 Google Apps 脚本中,而是在我的 javascript 中。愚蠢地认为它应该工作。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多