2 qq 28485505 qq_28485505 于 2016.09.11 15:10 提问

从数据库里面查询然后生成一个对象时出问题了,百思不得其解,想请教一下各位大神!
 public User findUser(String name, String password) {
        try {
            User user=qr.query("select * from users where name=? and password=?", new BeanHandler<User>(User.class),name,password);
            return user==null?null:user;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

这是代码片段
java.lang.RuntimeException: java.sql.SQLException: Cannot create com.utin.domain.User: com.utin.domain.User Query: select * from users where name=? and password=? Parameters: [mhg, 123]
at com.utin.dao.impl.UserDaoImpl.findUser(UserDaoImpl.java:30)
at com.utin.service.impl.UserServiceImpl.login(UserServiceImpl.java:14)
at com.utin.test.UserTest.testLogin(UserTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: Cannot create com.utin.domain.User: com.utin.domain.User Query: select * from users where name=? and password=? Parameters: [mhg, 123]
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.utin.dao.impl.UserDaoImpl.findUser(UserDaoImpl.java:27)
... 25 more

这是错误信息

1个回答

Veggiel
Veggiel   2016.09.11 15:47

你的数据库表名和你建立的映射关系的JavaBean名字不一致吧

Csdn user default icon
上传中...
上传图片
插入图片