请老师帮忙看看我这个报错信息,说获取数据表中的开始时间是出错
问题描述:
在测试代码时,提示说获取 start_time 这个列时出现错误
相关截图:
在Navicat中使用此sql查询语句是能正常看到数据的,start_time也能看到存在数据
相关代码:
package com.imooc.oa.dao;
import com.imooc.oa.entity.LeaveForm;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface LeaveFormDao {
public void insert(LeaveForm form);
public List<Map> selectByParams(@Param("pf_state") String pfState,@Param("pf_operator_id") Long operatorId);
}
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.oa.dao.LeaveFormDao">
<insert id="insert" parameterType="com.imooc.oa.entity.LeaveForm"
useGeneratedKeys="true" keyColumn="form_id" keyProperty="formId">
INSERT INTO adm_leave_form ( employee_id, form_type, start_time, end_time, reason, create_time, state) VALUES ( #{employeeId}, #{formType}, #{startTime}, #{endTime}, #{reason}, #{createTime}, #{state})
</insert>
<select id="selectByParams" parameterType="java.util.Map" resultType="java.util.Map">
select f.* ,e.name , d.*
from
adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d
where
f.form_id = pf.form_id
and f.employee_id = e.employee_id
and e.department_id = d.department_id
and pf.state = #{pf_state} and pf.operator_id = #{pf_operator_id}
</select>
</mapper>
package com.imooc.oa.dao;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.utils.MybatisUtils;
import junit.framework.TestCase;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class LeaveFormDaoTest extends TestCase {
public void testInsert(){
MybatisUtils.executeUpdate(sqlSession ->{
LeaveForm leaveForm = new LeaveForm();
leaveForm.setEmployeeId(3l);
leaveForm.setFormType(1);
leaveForm.setReason("回家谈情");
Date start = null;
Date end = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
start = sdf.parse("2020-1-1 15:00:00");
end = sdf.parse("2020-1-2 15:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
leaveForm.setStartTime(start);
leaveForm.setEndTime(end);
leaveForm.setCreateTime(new Date());
leaveForm.setState("processing");
sqlSession.getMapper(LeaveFormDao.class).insert(leaveForm);
return null;
});
}
public void testSelectByParams(){
MybatisUtils.executeQuery(sqlSession -> {
LeaveFormDao leaveFormDao =sqlSession.getMapper(LeaveFormDao.class);
List<Map> list= leaveFormDao.selectByParams("process",2l);
System.out.println(list);
return list;
});
}
}
package com.imooc.oa.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.Reader;
import java.util.function.Function;
public class MybatisUtils {
private static SqlSessionFactory sqlSessionFactory = null;
static {
Reader reader = null;
try {
reader = Resources.getResourceAsReader("mybatis-config.xml");
//初始化SqlSessionFactory对象
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
}catch (Exception e){
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
//实现sql查询操作,并返回结果
public static Object executeQuery(Function<SqlSession,Object> fun){
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Object object = fun.apply(sqlSession);
return object;
}finally{
sqlSession.close();
}
}
/**
* 数据写入操作
* @param fun Lambad表达式
* @return
*/
public static Object executeUpdate(Function<SqlSession,Object> fun){
SqlSession sqlSession = sqlSessionFactory.openSession(false);
try {
Object object = fun.apply(sqlSession);
sqlSession.commit();
return object;
}catch(RuntimeException e){
sqlSession.rollback();
throw e;
}
finally{
sqlSession.close();
}
}
}
相关代码:
报错信息
G:\JDK\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:G:\IDEA\IntelliJ IDEA 2021.1.3\lib\idea_rt.jar=55753:G:\IDEA\IntelliJ IDEA 2021.1.3\bin" -Dfile.encoding=UTF-8 -classpath "G:\IDEA\IntelliJ IDEA 2021.1.3\lib\idea_rt.jar;G:\IDEA\IntelliJ IDEA 2021.1.3\plugins\junit\lib\junit5-rt.jar;G:\IDEA\IntelliJ IDEA 2021.1.3\plugins\junit\lib\junit-rt.jar;G:\JDK\jre\lib\charsets.jar;G:\JDK\jre\lib\deploy.jar;G:\JDK\jre\lib\ext\access-bridge-64.jar;G:\JDK\jre\lib\ext\cldrdata.jar;G:\JDK\jre\lib\ext\dnsns.jar;G:\JDK\jre\lib\ext\jaccess.jar;G:\JDK\jre\lib\ext\jfxrt.jar;G:\JDK\jre\lib\ext\localedata.jar;G:\JDK\jre\lib\ext\nashorn.jar;G:\JDK\jre\lib\ext\sunec.jar;G:\JDK\jre\lib\ext\sunjce_provider.jar;G:\JDK\jre\lib\ext\sunmscapi.jar;G:\JDK\jre\lib\ext\sunpkcs11.jar;G:\JDK\jre\lib\ext\zipfs.jar;G:\JDK\jre\lib\javaws.jar;G:\JDK\jre\lib\jce.jar;G:\JDK\jre\lib\jfr.jar;G:\JDK\jre\lib\jfxswt.jar;G:\JDK\jre\lib\jsse.jar;G:\JDK\jre\lib\management-agent.jar;G:\JDK\jre\lib\plugin.jar;G:\JDK\jre\lib\resources.jar;G:\JDK\jre\lib\rt.jar;G:\IDEAwork\imooc-oa\target\test-classes;G:\IDEAwork\imooc-oa\target\classes;C:\Users\71901\.m2\repository\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;C:\Users\71901\.m2\repository\mysql\mysql-connector-java\8.0.25\mysql-connector-java-8.0.25.jar;C:\Users\71901\.m2\repository\com\google\protobuf\protobuf-java\3.11.4\protobuf-java-3.11.4.jar;C:\Users\71901\.m2\repository\com\alibaba\druid\1.1.14\druid-1.1.14.jar;C:\Users\71901\.m2\repository\junit\junit\4.13\junit-4.13.jar;C:\Users\71901\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\71901\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\71901\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\71901\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\71901\.m2\repository\org\freemarker\freemarker-gae\2.3.31\freemarker-gae-2.3.31.jar;C:\Users\71901\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\71901\.m2\repository\com\alibaba\fastjson\1.2.62\fastjson-1.2.62.jar;C:\Users\71901\.m2\repository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit3 com.imooc.oa.dao.LeaveFormDaoTest,testSelectByParams
[main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited
[main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
[main] DEBUG o.a.i.t.jdbc.JdbcTransaction - Opening JDBC Connection
[main] DEBUG o.a.i.t.jdbc.JdbcTransaction - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@7c37508a]
[main] DEBUG c.i.o.d.LeaveFormDao.selectByParams - ==> Preparing: select f.* ,e.name , d.* from adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d where f.form_id = pf.form_id and f.employee_id = e.employee_id and e.department_id = d.department_id and pf.state = ? and pf.operator_id = ?
[main] DEBUG c.i.o.d.LeaveFormDao.selectByParams - ==> Parameters: process(String), 2(Long)
[main] DEBUG o.a.i.t.jdbc.JdbcTransaction - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@7c37508a]
[main] DEBUG o.a.i.t.jdbc.JdbcTransaction - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@7c37508a]
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'start_time' from result set. Cause: java.sql.SQLFeatureNotSupportedException
### The error may exist in mappers/leave_form.xml
### The error may involve com.imooc.oa.dao.LeaveFormDao.selectByParams
### The error occurred while handling results
### SQL: select f.* ,e.name , d.* from adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d where f.form_id = pf.form_id and f.employee_id = e.employee_id and e.department_id = d.department_id and pf.state = ? and pf.operator_id = ?
### 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.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy4.selectByParams(Unknown Source)
at com.imooc.oa.dao.LeaveFormDaoTest.lambda$testSelectByParams$1(LeaveFormDaoTest.java:42)
at com.imooc.oa.utils.MybatisUtils.executeQuery(MybatisUtils.java:29)
at com.imooc.oa.dao.LeaveFormDaoTest.testSelectByParams(LeaveFormDaoTest.java:40)
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 junit.framework.TestCase.runTest(TestCase.java:177)
at junit.framework.TestCase.runBare(TestCase.java:142)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:130)
at junit.framework.TestSuite.runTest(TestSuite.java:241)
at junit.framework.TestSuite.run(TestSuite.java:236)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
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:83)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:521)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:402)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:354)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:328)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
... 26 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.$Proxy8.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:81)
... 40 more
Process finished with exit code -1
尝试过的解决方式:
使用过老师课程的源码进行测试未出现此错误,应该是我代码有问题,但是对比老师的源码,没有发现问题出在哪儿,请老师帮忙看看是我哪儿出了问题
25
收起
正在回答
1回答
同学你好,这个报错可能是依赖的版本冲突造成的问题,建议同学检查一下Mybatis和druid的依赖版本是否和源码中的一样,如果不一样,建议修改再试试。
祝学习愉快~
java工程师2020版
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星