2

Ok so i'll demonstrate my problem on tutorial code from https://developers.google.com/apps-script/jdbc

function insert() {
  var conn = Jdbc.getConnection("jdbc:mysql://<host>:<port>/<instance>", "user", "password");

  conn.setAutoCommit(false);
  var stmt = conn.prepareStatement("insert into person (lname,fname) values (?,?)");
  var start = new Date();
  for (var i = 0; i < 5000; i++) {
    // Objects are accessed using 1-based indexing
    stmt.setObject(1, 'firstName' + i);
    stmt.setObject(2, 'lastName' + i);
    stmt.addBatch();
  }
  var res = stmt.executeBatch();
  conn.commit();
  conn.close();
  var endTime = new Date();
  Logger.log("time is " + (endTime.getTime() - start.getTime()) + "ms");
  Logger.log("res has " + res.length);
}

Im from slovakia and we have special characters like žťščľýá after i change this line

stmt.setObject(1, 'firstName' + i);

to

stmt.setObject(1, 'žťščľýá' + i);

I'll get ???? in my db.I have utf8_general_ci in my db and my table picture

I've seen this JDBC Service with MySQL : UTF-8 encoding / decoding and tried Utilities.newBlob("").setDataFromString("foo", "UTF-8").getDataAsString("UTF-16") also this JDBC character encoding where lot of people are suggesting to use ?characterEncoding=utf8 after my connection link but i'll get error message.

4

1 回答 1

0

我可以使用您在那里的字符成功地写入Google Cloud SQL (MySQL 5.5)。那是我可以访问的唯一 MySQL 数据库。

你会看到一个我称之为动物的简单表在其中得到了正确的数据。我什至尝试过日语,效果很好。

在此处输入图像描述

这是我使用的代码 -

function writeEncodingIssue() {
  var conn = Jdbc.getCloudSqlConnection("jdbc:google:rdbms://<MY_INTSANCE_NAME>/mysql");
  conn.setAutoCommit(false);
  var stmt = conn.prepareStatement("insert into animals (name) values (?)");
  for (var i = 0; i < 2; i++) {
    stmt.setObject(1, 'žťščľýá' + i);//ショッピング
    stmt.addBatch();
  }
  var res = stmt.executeBatch();
  conn.commit();
  conn.close();
}

也许您可以尝试用 Java 或其他东西编写一个测试程序,以将其隔离为 Apps 脚本问题?

编辑:我已经能够用 MySQL 重现这个问题。问题跟踪器项目已更新。Apps 脚本团队正在对此进行调查。

于 2013-05-05T22:15:27.710 回答