为了账号安全,请及时绑定邮箱和手机立即绑定

提问!谢谢大家

java.lang.NullPointerException
com.xaccp.util.BaseDao.query(BaseDao.java:64)
com.xaccp.dao.impl.UserInfoDaoImpl.findById(UserInfoDaoImpl.java:51)
com.xaccp.dao.impl.UserInfoDaoImpl.addUserInfo(UserInfoDaoImpl.java:18)
com.xaccp.servlet.UserServlet.doReg(UserServlet.java:95)
com.xaccp.servlet.UserServlet.doPost(UserServlet.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

出现这个问题 获取不到值 代码如下:

public class UserInfoDaoImpl extends BaseDao implements UserInfoDao {


public int addUserInfo(UserInfo userInfo) {


UserInfo findById = findById(userInfo.getUsername());

if (findById != null) {

return -2;

}


String sql = "insert into UserInfo  (username, password, email) values (?,?,?)";

Object[] objs = { userInfo.getUsername(), userInfo.getPassword(),

userInfo.getEmail() };

int res = super.update(sql, objs);


return res;

}


public int updUserInfo(UserInfo userInfo) {

String sql = "update student set password = ?,email = ? where username = ?";

Object[] objs = { userInfo.getUsername(), userInfo.getPassword(),

userInfo.getEmail() };

return super.update(sql, objs);


}


public int delUserInfo(String username) {

String sql = "delete userInfo where username = ?";

Object[] objs = { username };

return super.update(sql, objs);


}


public UserInfo findById(String username) {

UserInfo info = null;

String sql = "select * from userInfo where username=?";

Object[] objs = { username };


ResultSet rs = super.query(sql, objs);

try {

if (rs.next()) {

info = new UserInfo();

info.setUsername(rs.getString("userName"));

info.setPassword(rs.getString("passWord"));

info.setEmail(rs.getString("email"));

}

} catch (SQLException e) {

}

super.closeAll();

return info;


}


public List<UserInfo> findAll() {

List<UserInfo> list = new ArrayList<UserInfo>();


String sql = "select * from UserInfo order by username";


ResultSet rs = super.query(sql, null);

try {

while (rs.next()) {

UserInfo info = new UserInfo();

info.setUsername(rs.getString("userName"));

info.setPassword(rs.getString("passWord"));

info.setEmail(rs.getString("email"));


list.add(info);

}

} catch (SQLException e) {

}

super.closeAll();

return list;

}


public UserInfo findUsernameAndPwd(String username, String password) {

UserInfo info = null;

String sql = "select * from UserInfo where  username=? and password=?";

Object[] objs = { username, password };

ResultSet rs = super.query(sql, objs);

try {

if (rs.next()) {

info = new UserInfo();

info.setUsername(rs.getString("userName"));

info.setPassword(rs.getString("passWord"));

}

} catch (SQLException e) {

e.printStackTrace();

}

super.closeAll();

return info;

}


}


正在回答

1 回答

UserInfo findById = findById(userInfo.getUsername());//局部变量名与函数名一样?

if (findById != null) {

return -2;

}

这里逻辑对吗?一般都是==null才提前返回的。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

提问!谢谢大家

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信