如何在Google Apps脚本中合并连接?

pjsm

以前,在Google Apps脚本中编写脚本时,我在所有功能中都打开和关闭了Jdbc连接。

为了加快我的应用程序的速度,似乎最好保持连接打开并在另一个功能中使用它。但是,我不知道如何在Google Apps脚本中执行此操作

谁能给我建议或示例?

布鲁阿劳霍

这是一个如何在ScriptDB上保留连接的示例。

function myFunction() {
  var conn = ScriptDb.getMyDb().query({name : "my_connection"} );
  var connection = null;
  var itemId = null;

  if(conn.getSize() == 0) {
    Logger.log(" Connection not found, creating new one");
    connection = Jdbc.getConnection('jdbc:mysql://<host>:3306/<instance>', 'user', 'password');
    itemId = ScriptDb.getMyDb().save({name : "my_connection", connection : connection}).getId();

  }else {
    Logger.log(" Connection found, retrieving "+conn.getSize());
    var dbItem  = conn.next();
    connection = dbItem.connection;
    itemId = dbItem.getId();
  }

  //Check if it is closed
  if(connection.isClosed()) {
    connection = Jdbc.getConnection('jdbc:mysql://<host>:3306/<instance>', 'user', 'password');

    //After opening remember to save to dabatase again and retain only one connection
    ScriptDb.getMyDb().removeById(itemId);
    ScriptDb.getMyDb().save({name : "my_connection", connection : connection});
  }

  //Use your connection here

  //Remenber to close it based in some criteria
}

这里的例子

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Google Apps脚本中将CSS连接到html

来自分类Dev

如何在Google Apps脚本中呈现Google Pay按钮

来自分类Dev

如何在Google Apps脚本中缓存对象

来自分类Dev

如何在Google Apps脚本中获取文件ID

来自分类Dev

如何在Google Apps脚本中获取Blob对象的大小?

来自分类Dev

如何在本地调试Google Apps脚本?

来自分类Dev

如何在新的Google Apps脚本IDE中查看脚本属性

来自分类Dev

Google Apps脚本:如何在Google文档中查找listItem对象并向其中插入项目?

来自分类Dev

如何在Google Apps脚本(Google Drive API)中向Blob添加/附加字符串

来自分类Dev

如何在Google Apps脚本中将按钮连接到另一个电子表格中的功能?

来自分类Dev

如何限制Google Apps脚本中的行数?

来自分类Dev

通过Google Apps脚本的分页合并从获取的API中获取的对象数组

来自分类Dev

跳过Google Apps脚本邮件合并中的空白电子邮件

来自分类Dev

如何从Google Apps脚本连接到Facebook Graph API?

来自分类Dev

如何在Google Apps脚本中的javascript中引用HtmlTemplate变量

来自分类Dev

Google Apps脚本中JDBC连接的URL参数中的SSL属性

来自分类常见问题

如何在执行该项目中功能的Google Apps脚本网络应用中创建按钮?

来自分类Dev

Google Apps脚本:选择后如何在文档中追加表格

来自分类Dev

如何在Google Apps脚本中获取“此”文件的当前实例?

来自分类Dev

如何在Google Apps脚本中模拟搜索和替换范围

来自分类Dev

如何在Google Apps脚本中修复{“ result”:“ error”,“ error”:{“ name”:“ Exception”}}

来自分类Dev

Google Apps脚本:如何在.gs文件中运行所有功能?

来自分类Dev

如何在Google Apps脚本中以编程方式为打开事件创建触发器

来自分类Dev

如何在Google Drive Apps脚本中创建快捷方式而不是多个父级

来自分类Dev

如何在Google Apps脚本中对表示不同数据集的嵌套数组进行排序?

来自分类Dev

如何在Google Apps脚本中获取多个上传图像的Base64内容?

来自分类Dev

如何在Google Apps脚本中的不同电子表格之间复制条件格式

来自分类Dev

如何在执行该项目中功能的Google Apps脚本网络应用中创建按钮?

来自分类Dev

如何在Google Apps脚本中输入特定的文件夹ID?

Related 相关文章

  1. 1

    如何在Google Apps脚本中将CSS连接到html

  2. 2

    如何在Google Apps脚本中呈现Google Pay按钮

  3. 3

    如何在Google Apps脚本中缓存对象

  4. 4

    如何在Google Apps脚本中获取文件ID

  5. 5

    如何在Google Apps脚本中获取Blob对象的大小?

  6. 6

    如何在本地调试Google Apps脚本?

  7. 7

    如何在新的Google Apps脚本IDE中查看脚本属性

  8. 8

    Google Apps脚本:如何在Google文档中查找listItem对象并向其中插入项目?

  9. 9

    如何在Google Apps脚本(Google Drive API)中向Blob添加/附加字符串

  10. 10

    如何在Google Apps脚本中将按钮连接到另一个电子表格中的功能?

  11. 11

    如何限制Google Apps脚本中的行数?

  12. 12

    通过Google Apps脚本的分页合并从获取的API中获取的对象数组

  13. 13

    跳过Google Apps脚本邮件合并中的空白电子邮件

  14. 14

    如何从Google Apps脚本连接到Facebook Graph API?

  15. 15

    如何在Google Apps脚本中的javascript中引用HtmlTemplate变量

  16. 16

    Google Apps脚本中JDBC连接的URL参数中的SSL属性

  17. 17

    如何在执行该项目中功能的Google Apps脚本网络应用中创建按钮?

  18. 18

    Google Apps脚本:选择后如何在文档中追加表格

  19. 19

    如何在Google Apps脚本中获取“此”文件的当前实例?

  20. 20

    如何在Google Apps脚本中模拟搜索和替换范围

  21. 21

    如何在Google Apps脚本中修复{“ result”:“ error”,“ error”:{“ name”:“ Exception”}}

  22. 22

    Google Apps脚本:如何在.gs文件中运行所有功能?

  23. 23

    如何在Google Apps脚本中以编程方式为打开事件创建触发器

  24. 24

    如何在Google Drive Apps脚本中创建快捷方式而不是多个父级

  25. 25

    如何在Google Apps脚本中对表示不同数据集的嵌套数组进行排序?

  26. 26

    如何在Google Apps脚本中获取多个上传图像的Base64内容?

  27. 27

    如何在Google Apps脚本中的不同电子表格之间复制条件格式

  28. 28

    如何在执行该项目中功能的Google Apps脚本网络应用中创建按钮?

  29. 29

    如何在Google Apps脚本中输入特定的文件夹ID?

热门标签

归档