Google Apps脚本 - JDBC连接失败 [英] Google Apps Script - JDBC Connection Failed

查看:191
本文介绍了Google Apps脚本 - JDBC连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Google Apps Developers参考资料( https://developers.google.com/apps-script/jdbc

 函数insert(){
var conn = Jdbc.getConnection(jdbc:mysql:// localhost:3306 / test,a,a);

错误:无法建立数据库连接。检查连接字符串,用户名和密码。 (第56行)



我尝试用我的特定IP地址替换localhost。

使用Access,ODBC和上述证书成功连接到我的数据库,所以我知道这是一个JDBC / Google应用程序脚本问题。



CLASSPATH指向正确的jar文件如下所示:

  C:\> echo%CLASSPATH%
。; C:\程序文件\Java\mysql-connector-java-5.1.22\mysql-connector-java-5.1.22-
bin.jar

我不确定是否需要在脚本或Google文档电子表格中或Windows内进行其他操作,以正确设置。



我从我读过的一个东西了解到,没有必要安装JDBC驱动程序,但我希望能够确认它。



<我花了很长时间在互联网上搜索解决方案,但无济于事。



我在诊断问题的位置时遇到问题m谎言,并会非常感谢任何人可能有这方面的想法。

解决方案

问题是 localhost 用作主机。 Google Apps脚本在Google服务器上执行,而不是在本地计算机上执行。这意味着脚本无法访问 localhost ,并且错误是逻辑的。



为了摆脱错误,必须在本地网络之外访问SQL Server(公共互联网)。它可以是转发到防火墙或第三方公共SQL服务后面的MySQL端口。

在互联网上搜索,我发现了一些公共的MySQL服务器,但我不知道它们是否在线或不在线( link#1 link#2 link#3

更新00 :JDBC服务有一个错误,无法将主机名解析为IP。我试图使用下面的代码进行测试。它连接到数据库。

  function test(){
var connection = Jdbc.getConnection(jdbc :mysql://193.62.203.76:3306 /,anonymous,);
调试器;
}


I am attempting to open a connection from a Google Apps Spreadsheet without success, using example code from the Google Apps Developers reference (https://developers.google.com/apps-script/jdbc)

function insert() {
    var conn = Jdbc.getConnection("jdbc:mysql://localhost:3306/test", "a", "a");

ERROR: Failed to establish a database connection. Check connection string, username and password. (line 56)

I have tried replacing "localhost" with my specific IP address.

I am able to connect successfully to my database using Access, ODBC and the above credentials so I know it's a JDBC / Google-apps-script issue.

CLASSPATH points to the correct jar file as shown by:

C:\>echo %CLASSPATH%
.;C:\Program Files\Java\mysql-connector-java-5.1.22\mysql-connector-java-5.1.22-
bin.jar

I am not sure if I have to do anything else, either within my script or google-doc-spreadsheet, or within Windows to set things up correctly.

I understand from one thing I read, that it is not necessary to install the JDBC driver as such but I would appreciate confirmation of same.

I have spent a long time searching the internet for solutions but to no avail.

I am having trouble diagnosing where the problem lies and would greatly appreciate any thoughts anyone may have in that regard.

解决方案

The problem is that the localhost is used as the host. Google Apps Scripts are executed on Google servers and not on local computers. This means that the scripts cannot access the localhost and the error is logical.

To get rid of the error is necessary to have an SQL Server accessible outside of a local network (public in internet). It can be a MySQL port forwarded behind of a firewall or a 3rd part public SQL service.

Searching in internet, I found a few public MySQL Servers, but I don not know either they are online or not (link #1, link #2, link #3)

Update 00: The JDBC Service has a bug with impossibility to resolve host name to IP. I tried to test using the following code. It makes a connection to the DB.

function test() {
  var connection = Jdbc.getConnection("jdbc:mysql://193.62.203.76:3306/", "anonymous", "");
  debugger;
}

这篇关于Google Apps脚本 - JDBC连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆