将数据从excelfile写入数据库时​​发生编码错误(mysql) [英] Encoding error while writing data from excelfile to database (mysql)

查看:94
本文介绍了将数据从excelfile写入数据库时​​发生编码错误(mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写入数据库时​​出现此错误:

I get this error when writing to database:

Encoding::UndefinedConversionError "\xD0" from ASCII-8BIT to UTF-8

谷歌搜索了一下之后,问题似乎出在Ruby 1.9.2字符串处理上,但是找不到真正的解决方案.

After googling around a bit the problem seems to lie in ruby 1.9.2 string handling but no real solution found.

我使用magic_encoding对所有数据强制使用utf-8.我的数据库也在utf-8上运行.

I use magic_encoding to force utf-8 on all data. My database runs on utf-8 as well.

我正在运行Rails 3.1和ruby 1.9.2.

I'm running rails 3.1 and ruby 1.9.2.

有人能对此错误有所启发吗?

Anyone that can shine some light on this error?

推荐答案

您应将此行添加到.rb文件的顶部

You should add this line to the top of your .rb file

# encoding: utf-8

或者您可以使用此宝石

magic_encoding

相关主题:

添加#编码:utf-8";到所有文件

这篇关于将数据从excelfile写入数据库时​​发生编码错误(mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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