一、BLOB字段
BLOB是指二进制大对象也就是英文Binary Large Object的所写,而CLOB是指大字符对象也就是英文Character Large Object的所写。其中BLOB是用来存储大量二进制数据的;CLOB用来存储大量文本数据。BLOB通常用来保存图片、文件等二进制类型的数据。 二、使用mybatis操作blob 1、表结构如下:
create table BLOB_FIELD
(
ID VARCHAR2(64 BYTE) not null,
TAB_NAME VARCHAR2(64 BYTE) not null,
TAB_PKID_VALUE VARCHAR2(64 BYTE) not null,
CLOB_COL_NAME VARCHAR2(64 BYTE) not null,
CLOB_COL_VALUE CLOB,
constraint PK_BLOB_FIELD primary key (ID)
);
2、实体代码如下:
package com.test.entity;
import java.sql.Clob;
/**
* 大字段
*/
public class BlobField {
private String tabName;// 表名
private String tabPkidValue;// 主键值
private String blobColName;// 列名
private byte[] blobColValue;// 列值 clob类型
public String getTabName() {
return tabName;
}
public void setTabName(String tabName) {
this.tabName = tabName;
}
public String getTabPkidValue() {
return tabPkidValue;
}
public void setTabPkidValue(String tabPkidValue) {
this.tabPkidValue = tabPkidValue;
}
public String getBlobColName() {
return blobColName;
}
public void setBlobColName(String blobColName) {
this.blobColName = blobColName;
}
public byte[] getBlobColValue() {
return blobColValue;
}
public void setBlobColValue(byte[] blobColValue) {
this.blobColValue = blobColValue;
}
}
3、mybatis sql代码如下:
<?xml version="." encoding="UTF-" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper .//EN" "https://mybatis.org/dtd/mybatis--mapper.dtd">
<mapper namespace="com.test.dao.BlobFieldDao">
<sql id="blobFieldColumns">
a.ID AS id,
a.TAB_NAME AS tabName,
a.TAB_PKID_VALUE AS tabPkidValue,
a.BLOB_COL_NAME AS blobColName,
a.BLOB_COL_VALUE AS blobColValue
</sql>
<sql id="blobFieldJoins">
</sql>
<select id="get" resultType="blobField">
SELECT
<include refid="blobFieldColumns" />
FROM BLOB_FIELD a
<include refid="blobFieldJoins" />
WHERE a.ID = #{id}
</select>
<select id="findList" resultType="blobField">
SELECT
<include refid="blobFieldColumns" />
FROM BLOB_FIELD a
<include refid="blobFieldJoins" />
</select>
<insert id="insert">
INSERT INTO BLOB_FIELD(
ID ,
TAB_NAME ,
TAB_PKID_VALUE ,
BLOB_COL_NAME ,
BLOB_COL_VALUE
) VALUES (
#{id},
#{tabName},
#{tabPkidValue},
#{blobColName},
#{blobColValue,jdbcType=BLOB}
)
</insert>
<update id="update">
UPDATE BLOB_FIELD SET
TAB_NAME = #{tabName},
TAB_PKID_VALUE = #{tabPkidValue},
BLOB_COL_NAME = #{blobColName},
BLOB_COL_VALUE = #{blobColValue}
WHERE ID = #{id}
</update>
<delete id="delete">
DELETE FROM BLOB_FIELD
WHERE ID = #{id}
</delete>
</mapper>