duan0714 2015-09-01 04:57
浏览 28
已采纳

在Golang中处理西班牙波浪

So I'm trying to enter this string into a mysql database using a sql driver. I get this error -

Do?a Merced Elementary
panic: Error 1366: Incorrect string value: '\x96a Mer...' for column 'name' at row 1

I thought about excluding this entry, but haven't been able to do so. I've tried -

if !strings.ContainsAny(splitStr[2], "U+0303") {
if !strings.ContainsAny(splitStr[2], '\x96') {

but that has not worked.

It would be better to have mysql deal with this, but I'm not sure how.

Any suggestions?

EDIT

This is how I connect to my db

db, err := sql.Open("mysql", "psanker:123@/education_data")
err = db.Ping()

db.SetMaxOpenConns(0)
check(err)
if err != nil {
    fmt.Println("Failed to prepare connection to database")
    log.Fatal("Error:", err.Error())
}

This is where my issue comes

districtResult, err := db.Exec("INSERT INTO districts(name) VALUES(?)", strings.TrimSpace(splitStr[2]))
check(err)

Output of SHOW CREATE TABLE

---------------------------------+
| Table     | Create Table                                                                                                                                                                                                                   |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| districts | CREATE TABLE `districts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#网络安全#的问题:非对称加密验证
      • ¥20 关于线性代数里施密特正交化和QR分解的疑问
      • ¥15 matlab超类包含解析错误
      • ¥15 python拖拽文件问题
      • ¥15 执行import paddle代码出现错误如何解决?
      • ¥15 hisat2align exited with value 137
      • ¥15 寻找大学生合作开发软件(Delphi)
      • ¥30 AndroidBench&eMMC内存测试速度&Android
      • ¥15 W10 文件共享失败 怎么解决
      • ¥20 b站私信完整导出的方法