package com.wh.starboot.model;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.io.ByteArrayInputStream;
import java.sql.*;
/**
* handle Blob as String
* <p>
* Created by kingbo on 2016/11/24.
*/
public class StringBlobTypeHandler extends BaseTypeHandler<String> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
byte[] bytes = parameter.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ps.setBinaryStream(i, bis, bytes.length);
}
@Override
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
Blob blob = rs.getBlob(columnName);
String returnValue = null;
if (null != blob) {
returnValue = new String(blob.getBytes(1L, (int) blob.length()));
}
return returnValue;
}
@Override
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
Blob blob = rs.getBlob(columnIndex);
String returnValue = null;
if (null != blob) {
returnValue = new String(blob.getBytes(1L, (int) blob.length()));
}
return returnValue;
}
@Override
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
Blob blob = cs.getBlob(columnIndex);
String returnValue = null;
if (null != blob) {
returnValue = new String(blob.getBytes(1L, (int) blob.length()));
}
return returnValue;
}
}
MyBatis用String处理blob
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 场景:Java将图标以Base64格式存储到数据库,字段使用Blob类型,然后通过Mybatis查询出来,直接在页...
- 问题描述:很多人在mybatis的xml中用到传参数实体类中包含list ,在xml中用foreach遍历时候,会...
- <resultMap type="Answer" id="answer"> <result property="a...
- cx_Oracle.BLOB是cx_Oracle.lob的一种类型,以二进制方式进行存储 cx_Oracle.BL...