java mybatis blob乱码
来源:互联网 发布:手机淘宝怎么刷新 编辑:程序博客网 时间:2024/06/01 07:50
package com.tybaby.mlportal.util;import java.io.ByteArrayInputStream;import java.io.UnsupportedEncodingException;import java.sql.Blob;import java.sql.CallableStatement;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import org.apache.ibatis.type.BaseTypeHandler;import org.apache.ibatis.type.JdbcType;public class MyBlobTypeHandler extends BaseTypeHandler<String>{//指定字符集 private static final String DEFAULT_CHARSET = "utf-8"; @Override public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { ByteArrayInputStream bis; try { //把String转化成byte流 bis = new ByteArrayInputStream(parameter.getBytes(DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Blob Encoding Error!"); } ps.setBinaryStream(i, bis, parameter.length()); } @Override public String getNullableResult(ResultSet rs, String columnName) throws SQLException { Blob blob = rs.getBlob(columnName); byte[] returnValue = null; if (null != blob) { returnValue = blob.getBytes(1, (int) blob.length()); } try { //把byte转化成string return new String(returnValue, DEFAULT_CHARSET); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Blob Encoding Error!"); } } @Override public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { Blob blob = cs.getBlob(columnIndex); byte[] returnValue = null; if (null != blob) { returnValue = blob.getBytes(1, (int) blob.length()); } try { return new String(returnValue, DEFAULT_CHARSET); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Blob Encoding Error!"); } }@Overridepublic String getNullableResult(ResultSet rs, int index) throws SQLException{Blob blob = rs.getBlob(index); byte[] returnValue = null; if (null != blob) { returnValue = blob.getBytes(1, (int) blob.length()); } try { //把byte转化成string return new String(returnValue, DEFAULT_CHARSET); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Blob Encoding Error!"); } } }
<result property="contentStr" column="content" typeHandler="com.tybaby.mlportal.util.MyBlobTypeHandler" />
0 0
- java mybatis blob乱码
- Mybatis中mysql blob类型乱码解决
- 解决mybatis获取mysql blob 乱码问题
- MyBatis解决BLOB中文乱码问题
- Java+mybatis+spring中读取BLOB类型异常
- mybatis blob 操作
- mybatis blob使用方式
- mybatis 存储blob数据
- mybatis 读取blob数据
- oracle blob mybatis 存取
- mybatis 存取blob
- java ibatis 读取mysql blob类型乱码 spring mvc文件下载csv文件乱码
- java+mybatis+mysql 中文乱码问题
- mybatis blob与clob处理
- BLOB类型中文乱码问题
- JAVA+ibatis+DB2:blob类型字段如何处理(解决中文乱码)
- Mysql Blob类型 转换为java String 时产生乱码的解决办法
- 从JAVA读取BLOB
- 超级厉害的JavaScript —— ECMAScript 6 标准(14) —— Module
- Linux和Mac查询端口占用
- Centos7更改默认启动桌面(或命令行)模式
- 通过PowerShell开源社区的Win32-OpenSSH来管理你的Windows服务器
- Win10系统任务栏时间不显示月份解决方法
- java mybatis blob乱码
- phpExcel 实现excel表格和mysql数据库的导入导出
- Mysql优化
- Dojo1.11官方教程文档翻译(5.4)Checkboxes
- ViewFlipper实现垂直轮播广告效果
- 数据结构之红黑树
- 【PAT】1006. Sign In and Sign Out
- Android全局异常捕获CrashHandler
- 无法正常启动DataNode