gpt4 book ai didi

google-apps-script - MySQL 的 JDBC 服务 : UTF-8 encoding/decoding

转载 作者:行者123 更新时间:2023-12-03 03:29:51 25 4
gpt4 key购买 nike

我尝试将 MySQL 数据库与 Google Drive 中的文档同步。我在 Google App Script 上编写了一个小脚本来完成这项工作。

我在处理字符编码时遇到一些问题(默认字符集是 UTF-8,整理为“general_ci”)。我尝试了不同的方法(encodeURIComponent、小型 UTF-8 工具类、Blob,...),但没有任何效果。这是小示例代码:

var title = result.getString("title");
title = Utilities.newBlob(title, Utilities.Charset.UTF_8);
if(title.getDataAsString() != file.getName()) {
Logger.log('Updating title for document %s from %s to %s', file.getId(), title.getDataAsString(), file.getName());
stmt_update_title.setObject(2, file.getId());
stmt_update_title.setObject(1, Utilities.newBlob(file.getName(), Utilities.Charset.UTF_8).getDataAsString());
stmt_update_title.addBatch();
}

当我从 MySQL 检索时,我得到一个带有“?”的错误字符串。而不是重音字符('é'、'è'、'à')。当我更新时,字符串已损坏(但它在日志中打印得很好)。

预先感谢您的帮助。

最佳答案

您需要为 JDBC 对象使用特殊的连接字符串,例如

jdbc:mysql://host:port/instance?useUnicode=true&characterEncoding=UTF-8

关于google-apps-script - MySQL 的 JDBC 服务 : UTF-8 encoding/decoding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13914545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com