ActiveRecord Sql Server中文问题2

下面代码在netbean下执行有问题,因为netbean的文件保存格式是utf-8.会报错存在多字节字符。
搞不明白。但如果直接存为ANSI即一切正常。记之
# coding : gb2312
require "rubygems"
gem 'activesupport', '=2.3.8'
require "active_record"
#require 'odbc_utf8'
require 'odbc'
require 'iconv'

conv=Iconv.new('GB2312','UTF-8')


ActiveRecord::Base.establish_connection(
    :adapter => "sqlserver",
    :mode=>"odbc",
    :dsn=>"localhost",
    :database=> "jkdb_sg",
    :username => "sa",
    :password => "123",
    :encoding=>"gb2312"
)

=begin
class MyModule < ActiveRecord::Base
 
  set_table_name "Module"
   set_primary_keys :RoadNo, :ModuleNo

end
=end


class Road < ActiveRecord::Base
  set_table_name "Road"
  set_primary_key "RoadNo"
end


Road.all().each do |r|
 #puts conv.iconv(r.RoadName)
 puts r.RoadName
end

=begin
r=Road.find(46)
r.RoadName='广珠西'
r.save
=end





puts "done"
puts "完成"












转载于:https://www.cnblogs.com/rubyist/archive/2010/10/13/1850404.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值