大家好,我在googlesheets脚本中遇到了一个wierd问题,mysql查询的显示和过滤由于其内容是俄语而无法工作
我将把整个脚本代码放在下面,但不起作用的主要部分是:
from samplename_order WHERE status = "Оплачен")');
以及
select (select data_create) as "Дата"
在第二个示例中,列标题呈现为“?”
在第一个例子中,除了列标题名,我什么都没有得到。
整个代码:
function onOpen() {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Sync', functionName: 'readData'}
];
spreadsheet.addMenu('Sync', menuItems);
}
var address = 'xxx:3306'; //ex. '10.1.1.1:1433'
var user = 'xxx';
var userPwd = 'xxxx';
var db = 'sxxxx';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
function readData() {
var conn = Jdbc.getConnection(dbUrl, user, userPwd);
var stmt = conn.createStatement();
stmt.setMaxRows(1000);
var results = stmt.executeQuery('select (select data_create) as "Дата",(select concat(name," ",sername)) as name,mail,(select concat(" ",phone)) as phone,comments,`status` from sample_order WHERE status = "Оплачен"');
var metaData=results.getMetaData();
var numCols = results.getMetaData().getColumnCount();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
results.close();
stmt.close();
sheet.autoResizeColumns(1, numCols+1);
}
2条答案
按热度按时间carvr3hs1#
将此添加到
getConnection()
电话:这里解释问号和其他常见的字符集问题
blpfk2vs2#
可能您应该在连接字符串中使用正确的字符编码选项。在这种情况下使用utf-8有一个很好的答案。