matlab mysql 查询,使用MATLAB从MySQL数据库检索Blob字段

I'm accessing public mySQL database using JDBC and mySQL java connector. exonCount is int(10), exonStarts and exonEnds are longblob fields.

javaaddpath('mysql-connector-java-5.1.12-bin.jar')

host = 'genome-mysql.cse.ucsc.edu';

user = 'genome';

password = '';

dbName = 'hg18';

jdbcString = sprintf('jdbc:mysql://%s/%s', host, dbName);

jdbcDriver = 'com.mysql.jdbc.Driver';

dbConn = database(dbName, user , password, jdbcDriver, jdbcString);

gene.Symb = 'CDKN2B';

% Check to make sure that we successfully connected

if isconnection(dbConn)

qry = sprintf('SELECT exonCount, exonStarts, exonEnds FROM refFlat WHERE geneName=''%s''',gene.Symb);

result = get(fetch(exec(dbConn, qry)), 'Data');

fprintf('Connection failed: %s\n', dbConn.Message);

end

Here is the result:

result =

[2] [18x1 int8] [18x1 int8]

[2] [18x1 int8] [18x1 int8]

result{1,2}'

ans =

50 49 57 57 50 57 48 49 44 50 49 57 57 56 54 55 51 44

This is wrong. The length of vectors in 2nd and 3rd columns should match the numbers in the 1st column.

The 1st blob, for example, should be [21992901; 21998673]. How I can convert it?

Update:

Just after submitting this question I thought it might be hex representation of a string.

And it was confirmed:

>> char(result{1,2}')

ans =

21992901,21998673,

So now I need to convert all blobs hex data into numeric vectors. Still thinking to do it in a vectorized way, since number of rows can be large.

解决方案

This will convert your character data to numeric vectors for all except the first column of data in result, placing the results back into the appropriate cells:

result(:,2:end) = cellfun(@(x) str2num(char(x'))',... %# Apply fcn to each cell

result(:,2:end),... %# Input cells

'UniformOutput',false); %# Output as a cell array

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值