DataRetrievalFailureException 为什么在下面代码会抛出这个异常

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:36:38
public List<UserInfo> queryById(UserInfo userInfo)
{
try
{
conn=dataSource.getConnection();
ptmt=conn.prepareStatement("select * from userInfo where [id]=?");
ptmt.setInt(1, userInfo.getId());
rs=ptmt.executeQuery();
List<UserInfo> list=new ArrayList<UserInfo>();
while(rs.next())
{
UserInfo user = new UserInfo();
user.setId(rs.getInt("id"));
user.setUsers(rs.getString("users"));
user.setPass(rs.getString("pass"));
list.add(user);

}
return list;
} catch (SQLException e)
{
throw new DataRetrievalFailureException("Retrieval failed.", e);

}
}

我不知你的数据库连接或一些变量名写错了没反正你看这一句
ptmt=conn.prepareStatement("select * from userInfo where [id]=?");
不知你的id为什么要加"[]"号,这肯定是不行的去掉这个中括号