Reprinted activerecord SQL Server Chinese Question 2

Source: Internet
Author: User

Activerecord SQL Server Chinese Question 2

Below 1CodeThere is a problem with the execution in netbean, because the file storage format of netbean is UTF-8. An error is reported that there are multi-byte characters.
View sourceprint? 1. I cannot understand it. However, if it is stored as ANSI, everything is normal. Note
View sourceprint? 01 # Coding: gb2312

02 require "rubygems"

03 gem 'activesupport', '= 2.3.8'

04 require "active_record"

05 # require 'odbc _ utf8'

06 require 'odbc'

07 require 'iconv'

08

09 Conv = iconv. New ('gb2312', 'utf-8 ')

10

11

12 activerecord: Base. establish_connection (

13: adapter => "sqlserver ",

14: mode => "ODBC ",

15: DSN => "localhost ",

16: Database => "jkdb_sg ",

17: username => "sa ",

18: Password => "123 ",

19: encoding => "gb2312"

20)

21

22 = begin

23 class mymodule <activerecord: Base

24

25 set_table_name "module"

26 set_primary_keys: roadno,: moduleno

27

28 end

29 = end

30

31

32 class road <activerecord: Base

33 set_table_name "road"

34 set_primary_key "roadno"

35 end

36

37

38 road. All (). Each do | r |

39 # Puts Conv. iconv (R. roadname)

40 puts R. roadname

41 end

42

43 = begin

44 r = road. Find (46)

45 R. roadname = 'guang Zhu Xi'

46 R. Save

47 = end

48

49

50

51

52

53 puts "done"

54 puts "finished"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.