类 MySQL8DateTimeSqlTypeFilter

java.lang.Object
javax.management.NotificationBroadcasterSupport
com.alibaba.druid.filter.FilterAdapter
com.alibaba.druid.filter.mysql8datetime.MySQL8DateTimeSqlTypeFilter
所有已实现的接口:
Filter, Wrapper, NotificationBroadcaster, NotificationEmitter

public class MySQL8DateTimeSqlTypeFilter extends FilterAdapter
针对mysql jdbc 8.0.23及以上版本,如果调用方没有使用orm框架,而是直接调用ResultSet的getObject方法,则针对DATETIME类型的字段,得到的对象从TimeStamp类型变成了LocalDateTime类型,导致调用方出现类型转换异常 通过Filter控制将对象类型转换成原来的类型
作者:
lizongbo
另请参阅:
  • 构造器详细资料

    • MySQL8DateTimeSqlTypeFilter

      public MySQL8DateTimeSqlTypeFilter()
  • 方法详细资料

    • resultSet_getObject

      public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException
      针对mysql jdbc 8.0.23及以上版本,通过该方法控制将对象类型转换成原来的类型
      指定者:
      resultSet_getObject 在接口中 Filter
      覆盖:
      resultSet_getObject 在类中 FilterAdapter
      参数:
      chain - chain the FilterChain object that represents the filter chain
      result - the ResultSetProxy object that represents the result set
      columnIndex - the index of the column to retrieve
      返回:
      an Object holding the column value, or null if the value is SQL NULL
      抛出:
      SQLException - if a database access error occurs or the columnIndex is invalid
      另请参阅:
    • resultSet_getObject

      public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException
      针对mysql jdbc 8.0.23及以上版本,通过该方法控制将对象类型转换成原来的类型
      指定者:
      resultSet_getObject 在接口中 Filter
      覆盖:
      resultSet_getObject 在类中 FilterAdapter
      参数:
      chain - chain the FilterChain object that represents the filter chain
      result - the ResultSetProxy object that represents the result set
      columnLabel - the label of the column to retrieve
      返回:
      an Object holding the column value, or null if the value is SQL NULL
      抛出:
      SQLException - if a database access error occurs or the columnLabel is invalid
      另请参阅:
    • getObjectReplaceLocalDateTime

      public static Object getObjectReplaceLocalDateTime(Object obj)
      Replaces a LocalDateTime object with its equivalent Timestamp object. If the input object is not an instance of LocalDateTime, it is returned as is. This method is specifically designed to handle cases where upgrading to MySQL JDBC 8.0.23 or above requires converting LocalDateTime objects back to the older compatible type.
      参数:
      obj - the object to be checked and possibly replaced
      返回:
      the replaced object if it is a LocalDateTime, or the original object otherwise
    • resultSet_getMetaData

      public ResultSetMetaData resultSet_getMetaData(FilterChain chain, ResultSetProxy resultSet) throws SQLException
      Retrieves the metadata for the result set, including information about the columns and their properties. This method wraps the original result set metadata with a custom implementation that handles MySQL 8.0.23 or above compatibility for LocalDateTime objects.
      指定者:
      resultSet_getMetaData 在接口中 Filter
      覆盖:
      resultSet_getMetaData 在类中 FilterAdapter
      参数:
      chain - the FilterChain object that represents the filter chain
      resultSet - the ResultSetProxy object that represents the result set
      返回:
      a ResultSetMetaData object containing the metadata for the result set
      抛出:
      SQLException - if a database access error occurs