Summary of common causes
1. The field name in the encapsulation set is inconsistent with the database column name. Check whether it is consistent and whether there is this field
2. Using Lombok or other operations results in no parameter free structure or no get/set
3. Use Druid, because the version problem leads to exception handling for the time type localdatetime.class; This solution: do not use druid or use other database connection sources for replacement or Druid version upgrade.
Let’s talk about the source of this exception first:
getResult in basetypehandler.java
public T getResult(ResultSet rs, String columnName) throws SQLException {
try {
// Map database fields and entity class attributes in the result set
return getNullableResult(rs, columnName);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set. Cause: " + e, e);
}
}
There will be exceptions before this exception, that is, the exception will be caused by many reasons, which means there will be many solutions for the exception. Here is the processing and positioning process of the third exception handling scheme.
problem scenario description
Query the qualified course record information by date. The time field in the entity class is starttime (Format: yyyy MM DD HH: mm: SS), and the field in the database is start_ Time, field type datetime.
Stack exception information (some stack information is deleted due to length reason):
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:87)
... 73 more
Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85)
... 99 more
Caused by: java.sql.SQLFeatureNotSupportedException
at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:1771)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69)
at com.sun.proxy.$Proxy190.getObject(Unknown Source)
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:38)
at org.apache.ibatis.type.LocalDateTimeTypeHandler.getNullableResult(LocalDateTimeTypeHandler.java:28)
at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85)
... 101 more
Look at the stack information from the beginning. Obviously, it is the exception thrown by getnullableresult in localdatetimetypehandler.java.The earliest exception information:
java.sql.sqlfeaturenotsupportedexception.
first look at getnullableresult in localdatetimetypehandler.java
public LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
return rs.getObject(columnName, LocalDateTime.class);
}
rs.getobject
has many implementation methods. Because the Druid database connection source is used (the original version is 1.0.28), you can directly locate GetObject in druidpooledresultset.java:
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
Looking through the source code according to druid1.0.28, it is found that localdatetime.Class
about date type processing instructions are not supported, and sqlfeaturenotsupportedexception
is thrown directly. Modify the Druid version in pom.xml, upgrade to 1.2.1, and then take a look at the implementation of this version:
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
try {
return this.rs.getObject(columnLabel, type);
} catch (Throwable var4) {
throw this.checkException(var4);
}
}
Note: the higher version supports localdatetime.Class
processing. It is normal after retesting!
Read More:
- [Solved] Error attempting to get column ‘xxxx_time‘ from result set. Cause: java.sql.SQLFeatureNotSupportedEx
- JAVA Error: Error attempting to get column ‘XXX’ from result set. Cause java.sql.
- [Solved] JavaErrors_mybatis collection column Pass Value Error
- Ruoyi-cloud Integrated mybatis-plus Error: Unknown column ‘search_value‘ in ‘field list‘
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- Using mybatis statement.getGenreatedKeys(); usegeneratedkeys = “true”; using self incrementing primary key to get primary key value policy and Oracle do not support self incrementing, Oracle uses sequence
- [Solved] Error updating database. Cause: java.sql.SQLException: Incorrect integer value: ‘**‘ for column
- How to Solve SQL comments error in the mybatis query
- Mybatis single parameter pass in exception (How to Fix)
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- [Solved] mybatis Error querying database. Cause: java.sql.SQLException: The server time zone value
- When the database table field is set to self incrementing, use the entity class to insert or update the data to solve the error (Hibernate Framework)
- Mybatis Error: The error may exist in xxxxMapper.xml [How to Solve]
- Mybatis sets the primary key Auto-Increment error: No setter found for the keyProperty
- Mybatis Error: Error instantiating class bakou.entity.Person with invalid types () or value)
- [Solved] Error getting generated key or setting result to parameter object. UnsupportedOperationException
- Build a mybatis and it will appear session.selectOne Method error
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error