java.sql.SQLException: Cannot create com.liqi.entry.User: com.liqi.entry.User Query: SELECT * from users where sex = ? Parameters: [女]
    at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:320)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:349)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:287)
    at com.liqi.test.Test1.queryUsers(Test1.java:66)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

错误原因:我在单元测试中User自提供了有参,忘记提供无参了。 在使用如下语句查询的时候,User作为参数传递了,我们这单元测试中需要提供相应的构造方法,这里是无参。

queryRunner.query(sql, new BeanListHandler<User>(User.class), "女")语句中的 new BeanListHandler<User>(User.class)  是以类的字节码为参数的,实际上就是利用无参构造器

解决办法:直接在模型中 加入无参构造函数,就OK了。

public void queryUsers(){QueryRunner queryRunner = new QueryRunner(DruidDBUtil.getDataSource());String sql = "SELECT * from users where sex = ?";try {List<User> userList = queryRunner.query(sql, new BeanListHandler<User>(User.class), "女");} catch (SQLException e) {e.printStackTrace();}}

java.sql.SQLException: Cannot create com.liqi.entry.User: com.li.entry.User Query: SELECT * from u相关推荐

  1. (java.sql.SQLException: Cannot create com.entity.Book: com.entity.Book ...: [1]解决方案)

    (java.sql.SQLException: Cannot create com.entity.Book: com.entity.Book -: [1]解决方案) 在学习jdbc的时候出现了这个错误 ...

  2. java.sql.SQLException: Cannot set createTime: incompatible types

    今日在写OrderDaoImpl类,进行测试一直报错,起初以为是Order类的名字与数据库不同引起,在查询函数中起了别名来解决,但一直报Cannot set createTime错误,上网找了说法,都 ...

  3. Oracle Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect

    参考:https://blog.csdn.net/qq_36326332/article/details/102938147 https://blog.csdn.net/fly_captain/art ...

  4. java.sql.SQLException: validateConnection false

    错误信息 详细信息 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.my ...

  5. nslang oracle_解决ojdbc14连接oracle报“java.sql.SQLException: Io 异常: Size Data Unit (SDU) mismatch”异常问题...

    一.前言 通过ojdbc14.jar连接oracle数据库,应用运行期间报出"java.sql.SQLException: Io 异常: Size Data Unit (SDU) misma ...

  6. java.sql.SQLException: ORA-01438: 值大于此列指定的允许精确度

    java.sql.SQLException:   ORA-01438:   值大于此列指定的允许精确度 请看:     SQL>   create   table   test   (num   ...

  7. java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)

    早上在做MyBatis+Spring整合的时候爆了个奇葩的bug: 十月 19, 2017 11:18:11 上午 org.springframework.context.support.Abstra ...

  8. java.sql.SQLException: Incorrect string value: '\xE6\x88\x91\xE7\x9A\x84...' for column 'groupName'

    今天使用mysql,用java程序往mysql中写数据,出现如下错误: java.sql.SQLException: Incorrect string value: '\xE6\x88\x91\xE7 ...

  9. java.sql.SQLException: Incorrect string value: ‘\xE4\xB8\x8A\xE6\xB5\xB7‘ for column ‘xxx‘

    解决:java.sql.SQLException: Incorrect string value: '\xE4\xB8\x8A\xE6\xB5\xB7' for column 'xxx' 在这位兄台这 ...

  10. java 提取违反顺序_oracle 中 java.sql.SQLException: ORA-01002: 提取违反顺序

    在一个流程中设置了一个机器人节点,目的是:审批结束后,通过update语句,将表单中的一些内容更新到数据库person_info_t的表中,并将更新前后的值记录到新表info_update_recor ...

最新文章

  1. Java中方法和工作内存的关系_JMM中工作内存和主内存的关系
  2. freebsd php 编译 mysql sql2005_问下:Freebsd下用php连接ms sql server
  3. ABAP TBL鼠标滚动到某行某列
  4. 助力小白常见JS逆向乱杀喂饭教程——Url加密
  5. 推荐曹济的FPA培训课程
  6. 【JMeter】Thread Group下的组件Sampler取样器
  7. 【码云周刊第 61 期】四款开源项目教你玩转微信游戏
  8. 为Visual Studio 2010增加ExtJs智能提示
  9. jsp mysql简单登录_简单的登录页面,实现增删改查运用jsp/servlet和mysql数据库免费分享...
  10. ubuntu的web服务器_如何在Ubuntu上安装OpenLiteSpeed Web服务器?
  11. 网站页面直接显示html代码 转义html代码 excel导入题库 解决方法
  12. CentOS6.x安装zabbix
  13. 论文阅读 || 图像分类系列 —— DenseNet(很详细)
  14. html实现酷狗歌词,酷狗音乐怎么制作歌词?酷狗音乐制作歌词的方法
  15. 无数本高清古籍善本下载,200多个G
  16. UML建模工具安装详细教程(StarUML 5.0.2)
  17. 你的网名OUT了吗?盘点那些曾经超in的网名
  18. Linux 人大金仓安装部署记录
  19. 我的新书《Flutter 开发之旅从南到北》终于和大家见面了(抽奖送书啦)。
  20. BFM:总线功能模型 zz

热门文章

  1. 洛谷 P1338 末日的传说
  2. Spine 2D骨骼动画教程-完整实例入门教程
  3. “店小二”精神国际化步伐23年成就巨无霸
  4. 内存分配函数总结- 陈敏的博客- CSDN博客
  5. 网络显示其他计算机不全,win7系统网络邻居显示不全只能看到2台计算机的解决方法...
  6. scannable dest type struct with >1 columns (3) in result
  7. 今天,你脸上还长痤疮吗?
  8. NetBIOS编程获取本机MAC地址及一个小坑
  9. B站网页下载视频(flv格式)
  10. javaScript常用案例