• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

matlab-VQB操作MYSQL数据库及中文乱码解决

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

首先安装好ODBC MYSQL驱动

(64位)

http://cdn.mysql.com/Downloads/Connector-ODBC/5.2/mysql-connector-odbc-5.2.2-winx64.msi

(32位)

http://cdn.mysql.com/Downloads/Connector-ODBC/5.2/mysql-connector-odbc-5.2.2-win32.msi

然后,打开vqb

查询



 

 

插入

 



 

 

MATLAB通过ODBC操作MYSQL的中文乱码,需要在数据源中进行配置



 

查询数据(中文乱码消失了)



 

 插入中文数据

>> y2={'追求'}

y2 =

    '追求'

>>



 测试一下,查看中文数据是否正确插入



 

 

此外,关于字符编码转换的2个函数

native2unicode

Convert numeric bytes to Unicode characters

Syntax

unicodestr = native2unicode(bytes)
unicodestr = native2unicode(bytes, encoding)

Description

unicodestr = native2unicode(bytes) takes a vector containing numeric values in the range [0,255] and converts these values as a stream of 8-bit bytes to Unicode characters. The stream of bytes is assumed to be in the MATLAB default character encoding scheme. Return value unicodestr is a char vector that has the same general array shape as bytes.

unicodestr = native2unicode(bytes, encoding) does the conversion with the assumption that the byte stream is in the character encoding scheme specified by the string encoding. encoding must be the empty string ('') or a name or alias for an encoding scheme. Some examples are 'UTF-8', 'latin1', 'US-ASCII', and 'Shift_JIS'. For common names and aliases, see the Web site http://www.iana.org/assignments/character-sets. If encoding is unspecified or is the empty string (''), the MATLAB default encoding scheme is used.

Note   If bytes is a char vector, it is returned unchanged.

Examples

This example begins with a vector of bytes in an unknown character encoding scheme. The user-written function detect_encoding determines the encoding scheme. If successful, it returns the encoding scheme name or alias as a string. If unsuccessful, it throws an error represented by an MException object, ME. The example calls native2unicode to convert the bytes to Unicode characters:

try
   enc = detect_encoding(bytes);
	   str = native2unicode(bytes, enc);
	   disp(str);
catch ME
	   rethrow(ME);
end

Note that the computer must be configured to display text in a language represented by the detected encoding scheme for the output of disp(str) to be correct.

 

================

unicode2native

Convert Unicode characters to numeric bytes

Syntax

bytes = unicode2native(unicodestr)
bytes = unicode2native(unicodestr, encoding)

Description

bytes = unicode2native(unicodestr) takes a char vector of Unicode characters, unicodestr, converts it to the MATLAB default character encoding scheme, and returns the bytes as a uint8 vector, bytes. Output vector bytes has the same general array shape as the unicodestr input. You can save the output of unicode2native to a file using the fwrite function.

bytes = unicode2native(unicodestr, encoding) converts the Unicode characters to the character encoding scheme specified by the string encoding. encoding must be the empty string ('') or a name or alias for an encoding scheme. Some examples are 'UTF-8', 'latin1', 'US-ASCII', and 'Shift_JIS'. For common names and aliases, see the Web site http://www.iana.org/assignments/character-sets. If encoding is unspecified or is the empty string (''), the MATLAB default encoding scheme is used.

Examples

This example begins with two strings containing Unicode characters. It assumes that string str1 contains text in a Western European language and string str2 contains Japanese text. The example writes both strings into the same file, using the ISO-8859-1 character encoding scheme for the first string and the Shift-JIS encoding scheme for the second string. The example uses unicode2native to convert the two strings to the appropriate encoding schemes.

fid = fopen('mixed.txt', 'w');
bytes1 = unicode2native(str1, 'ISO-8859-1');
fwrite(fid, bytes1, 'uint8');
bytes2 = unicode2native(str2, 'Shift_JIS');
fwrite(fid, bytes2, 'uint8');
fclose(fid);

 

 

 

  

 

 

报表输出

Display=>report



 

 

是否显示表头设置

display=>report generator

在这选择databaselbx.rpt

然后选择table-ans,可看到表头选项



 

 通过这种方式输出没有表头,我们修改y3变量,人为加上表头

>> y3=[{'名称'};y3]

y3 =

    '名称'
    '上大'
    '追求'

>>



 

 

逻辑型数

 



 

>> z2

z2 =

    '上大'    [1]
    '追求'    [0]

>>

 

逻辑型变量的输出形式如下:

>> insert(myconn,'myst',colnames,{'张三',logical(1)})


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi串口打印机打印发布时间:2022-07-18
下一篇:
Delphi之DLL知识学习4---创建DLL发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap