提问!谢谢大家
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;
}
}