欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java.sql.SQLException: Cannot create错误

程序员文章站 2022-04-30 14:02:23
...

用druid查询mysql里的数据

    @Test
    public void test2() throws Exception {
        User user = new User("liu", "abc");
        QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());
        User existUser = queryRunner.query("select * from userlogin where username = ? and password = ?", new BeanHandler<User>(User.class), user.getUsername(), user.getPassword());
//        System.out.println(Arrays.toString(existUser));
        System.out.println(existUser == null);
    }

报错:
java.sql.SQLException: Cannot create com.itheima.domain.User: com.itheima.domain.User Query: select * from userlogin where username = ? and password = ? Parameters: [liu, abc]

需要在User里面添加一个无参数的构造器

java.sql.SQLException: Cannot create错误
运行结果如下:
java.sql.SQLException: Cannot create错误