专业编程教程与实战项目分享平台

网站首页 > 技术文章 正文

sharding-jdbc oracle分表避坑(jdbctemplate分页查询oracle)

ins518 2024-11-16 22:17:10 技术文章 11 ℃ 0 评论

环境:springboot2.2.11 + shardingsphere4.0.1 + mybatis + oracle做分表操作。

shardingsphere4.0.1不支持oracle中的nvarchar数据类型,源码如下:

源码:

AbstractUnsupportedOperationResultSet.java

...
@Override
    public final String getNString(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNString");
    }
    
    @Override
    publicfinal  String getNString(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNString");
    }
....

这两个方法是final修饰的,所以要先重写AbstractUnsupportedOperationResultSet这个类将final去掉:


修改如下,去掉final修饰符。

@Override
    public String getNString(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNString");
    }
    
    @Override
    public String getNString(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getNString");
    }

重写ShardingResultSet.java

添加getNString两个方法

public String getNString(final int columnIndex) throws SQLException {
        return (String) ResultSetUtil.convertValue(mergeResultSet.getValue(columnIndex, String.class), String.class);
    }
    
    public String getNString(final String columnLabel) throws SQLException {
        int columnIndex = columnLabelAndIndexMap.get(getActualColumnLabel(columnLabel));
        return (String) ResultSetUtil.convertValue(mergeResultSet.getValue(columnIndex, String.class), String.class);
    }

shardingsphere坑比较多,与数据库驱动版本,mybatis的分页插件的版本都有一定的关系。

在我的项目中一开始用的分页插件版本是4.x版本结果遇到分页就报错,升级5.x版本后好了,好了!!!

关注,转发,谢谢!!!!

SpringBoot 分库分表sharding-sphere

SpringBoot分库分表sharding-sphere2

SpringBoot分库分表sharding-sphere3

shardingsphere数据加密(数据脱敏)

mybatis sharding-jdbc Java8日期

shardingsphere oracle各种问题总结

shardingsphere数据脱敏(自定义加密算法)

Redis查漏补缺

SpringMVC参数统一验证方法

SpringBoot2 整合 OAuth2 资源认证(保护)

SpringBoot2 整合OAuth2实现统一认证

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表