设为首页 收藏本站
查看: 446|回复: 0

[经验分享] matlab-VQB操作MYSQL数据库及中文乱码解决

[复制链接]

尚未签到

发表于 2016-10-17 03:31:55 | 显示全部楼层 |阅读模式
  首先安装好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
  查询
  
DSC0000.jpg
 
  
  插入
  
  
DSC0001.jpg
 
  
  MATLAB通过ODBC操作MYSQL的中文乱码,需要在数据源中进行配置
  
DSC0002.jpg
 
  查询数据(中文乱码消失了)
  
DSC0003.jpg
 
  插入中文数据
  >> y2={'追求'}
  y2 =
  '追求'
  >>
  
DSC0004.jpg
 测试一下,查看中文数据是否正确插入
  
DSC0005.jpg
 
  
  此外,关于字符编码转换的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
  
DSC0006.jpg
 
  
  是否显示表头设置
  display=>report generator
  在这选择databaselbx.rpt
  然后选择table-ans,可看到表头选项
  
DSC0007.jpg
 
  通过这种方式输出没有表头,我们修改y3变量,人为加上表头
  >> y3=[{'名称'};y3]
  y3 =
  '名称'
    '上大'
    '追求'
  >>
  
DSC0008.jpg
 
  
  逻辑型数
  
  
DSC0009.jpg
 
  >> z2
  z2 =
  '上大'    [1]
    '追求'    [0]
  >>
  
  逻辑型变量的输出形式如下:
  >> insert(myconn,'myst',colnames,{'张三',logical(1)})

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-287012-1-1.html 上篇帖子: [转载] 适合MySQL的Xeon 55XX系列CPU编译参数 下篇帖子: java访问mysql 数据库 表 的列名称
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表