zoukankan      html  css  js  c++  java
  • mybatis存取oracle长数据clob方法

    1.重写mybatis的sql执行器

    package com.ai.gridoperation;
    
    import org.apache.ibatis.type.JdbcType;
    import org.apache.ibatis.type.TypeHandler;
    
    import java.sql.*;
    
    
    /**
     * 解决保存数据字段超过4000 char 问题
     * @author yuans
     * @create 2020-06-02-14:38
     */
    public class OracleClobTypeHandler implements TypeHandler<Object> {
    
        @Override
        public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
            Clob clob = ps.getConnection().createClob();
            clob.setString(1, (String) parameter);
            ps.setClob(i, clob);
        }
    
        @Override
        public Object getResult(ResultSet rs, String columnName) throws SQLException {
            Clob clob =  rs.getClob(columnName);
            return (clob == null || clob.length() == 0) ? null : clob.getSubString((long) 1, (int) clob.length());
        }
    
        @Override
        public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
            return null;
        }
    
        @Override
        public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
            return null;
        }
    }
    

    2.保存使用

      INSERT INTO 
        GR_MICROGRID(example)
        VALUES(
          <if test=" shape !=null and shape !='' ">
               #{shape,typeHandler=com.ai.gridoperation.OracleClobTypeHandler}
          </if>)
    

    3.查询使用

     <resultMap id="microFormatsBorderId" type="java.util.HashMap">
            <result  column="polygon" property="polygon" 		       typeHandler="com.ai.gridoperation.OracleClobTypeHandler"/>
     </resultMap>
    
     <select id="microFormatsBorderQuery" parameterType="java.util.Map" resultMap="microFormatsBorderId">
            select polygon from table
     </select>
  • 相关阅读:
    LeetCode 334 Increasing Triplet
    LeetCode 笔记27 Two Sum III
    LeetCode 笔记28 Maximum Gap
    最小的图灵完备语言——BrainFuck
    蛋疼的SVG外部引用方式
    HackerRank# Hexagonal Grid
    HackerRank# The Longest Common Subsequence
    HackerRank# Bricks Game
    HackerRank# Fibonacci Modified
    HackerRank# Knapsack
  • 原文地址:https://www.cnblogs.com/ysit/p/13174253.html
Copyright © 2011-2022 走看看