Oracle+Mybatis插入Clob数据问题

本文介绍了一种针对Oracle数据库CLOB类型的处理器实现方法,并提供了具体的Java代码示例。该处理器能够处理CLOB类型的读写操作,包括从数据库中获取CLOB内容及设置CLOB值。此外还讨论了在MyBatis中使用此处理器的方式以及插入CLOB数据时需要注意的SQL语法问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<result column="content" property="content" jdbcType="CLOB" javaType="string" typeHandler="com.cn.handler.OracleClobTypeHandler" />

处理器代码:

package com.cn.handler;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import oracle.sql.CLOB;

public class OracleClobTypeHandler implements TypeHandler<Object>{

public Object valueOf(String param) {  
        return null;  
    }  
    @Override  
    public Object getResult(ResultSet arg0, String arg1) throws SQLException {  
        CLOB clob = (CLOB) arg0.getClob(arg1);  
        return (clob == null || clob.length() == 0) ? null : clob.getSubString((long) 1, (int) clob.length());  
    }  
    @Override  
    public Object getResult(ResultSet arg0, int arg1) throws SQLException {  
        return null;  
    }  
    @Override  
    public Object getResult(CallableStatement arg0, int arg1) throws SQLException {  
        return null;  
    }  
    @Override  
    public void setParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3) throws SQLException {  
        CLOB clob = CLOB.empty_lob();  
        clob.setString(1, (String) arg2);  
        arg0.setClob(arg1, clob);  
    }  

}

插入时注意:

<insert>

    insert into table(column,column...) values(value,value...)

</insert>

如果插入失败,则需要改成

<insert>

begin

    insert into table(column,column...) values(value,value...)

;end;

</insert>

2、CLOB类型不支持的语法有


呃呃呃呃


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值