List<UserLoginDTO> userDTOList=new ArrayList<UserLoginDTO>();
UserLoginDTO user= null;
try {
pstmt = conn.prepareStatement(NHMQueryConstant.GET_SEARCH_USER_DETAIL.toString());
pstmt.setString(1,searchUser);
rs = pstmt.executeQuery();
while (rs.next()) {
user= new UserLoginDTO();
//user= new UserLoginDTO();
//String login= rs.getString("Login_ID");
user.setUserId(rs.getInt("M_USER_ID"));
user.setUserName(rs.getString("M_USER_NAME"));
user.setLoginID(rs.getString("Login_ID"));
user.setUserTypeID(rs.getInt("USER_TYPE_ID"));
user.setPassword(rs.getString("PASSWORD"));
user.setMobile(rs.getString("MOB_NO"));
user.setEmail(rs.getString("EMAIL"));
userDTOList.add(user);
}
} catch (Exception e) {
throw new NHMException(e.getMessage());
}
public static final StringBuilder GET_SEARCH_USER_DETAIL =
new StringBuilder().
append(" SELECT * FROM m_user_master").
append(" WHERE M_User_Name = IFNULL(NULL,M_User_Name)
AND Login_id = IFNULL('?',Login_id) limit 1 ");
我在此代码中使参数索引超出范围。 请你纠正我
答案 0 :(得分:0)
不应引用sql查询中的占位符。正确的查询:
public static final StringBuilder GET_SEARCH_USER_DETAIL = new StringBuilder().append(" SELECT * FROM m_user_master").append(" WHERE M_User_Name = IFNULL(NULL,M_User_Name)AND Login_id = IFNULL(?,Login_id) limit 1 ");