mybatis中的坑(可以查询到结果但是不能输出)

通过Junit测试出现错误:

java.lang.AbstractMethodError: Method com/mysql/jdbc/PreparedStatement.isClosed()Z is abstract
    at com.mysql.jdbc.PreparedStatement.isClosed(PreparedStatement.java)
    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.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78)
  控制台可以进行打印输出参数和相应的日志文件:

DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - Opening JDBC Connection
DEBUG [main] - Created connection 561247961.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.Connection@2173f6d9]
DEBUG [main] - ==>  Preparing: select * from user where id= ? 
DEBUG [main] - ==> Parameters: 10(Integer)
DEBUG [main] - <==      Total: 1

但是不能打印出现你想要的结果以下是测试代码:

有打印语句可是控制台未能够输入查询到结果

@Test    
    public  void test1() throws IOException {
        // TODO Auto-generated method stub
        //加载核心配置文件
        String resource="sqlMapConfig.xml";
        InputStream   in= Resources.getResourceAsStream(resource);
        //创建SqlSessionFactory工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        //创建sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //执行sql语句,selectone:第一个参数是对的应的xml文件中的的id,第二个是对应的要传入的参数
        User user = sqlSession.selectOne("test.selectid", 10);
        System.out.println(user.getId());
        //释放资源
        sqlSession.close();
    }

解决方式:看了一遍所有的jar包,肯定与原来mybatis提供的jar包无关(最新版本的),再看下自己引入的数据库连接的jar包是5.0的,果断选着更换jar包把jar包更换到5.1.之后测试绿条;可以打印出:

DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
DEBUG [main] - Opening JDBC Connection
DEBUG [main] - Created connection 1970881185.
DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@757942a1]
DEBUG [main] - ==>  Preparing: select * from user where id= ? 
DEBUG [main] - ==> Parameters: 10(Integer)
DEBUG [main] - <==      Total: 1
10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kay三石

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值