如何通过数据库中的下拉值和单个字符进行搜索?

时间:2016-09-20 09:30:12

标签: java mysql

<select id="searchBy" name="userDTO.searchBy">
            <option id="1" value="1">NAME</option>
            <option id="2" value="2">Login ID</option>
            <option id="3" value="3">Email</option>
            <option id="4"  value="4">Mobile</option>
            </select> 
<s:textfield  id="searchName" label="searchName"  name="userDTO.userName"/>
<input type="button" value="createNew"  onClick="contentDisplay()" title="Create New Parameter" />




try {
            pstmt = conn.prepareStatement(SLCMQueryConstant.SEARCH_USER_DETAIL);
            pstmt.setInt(1,userDTO.getStateId());
            pstmt.setString(2, userDTO.getSerachBy());

            rs = pstmt.executeQuery();
            while (rs.next()) {
                UserDTO userDto = new UserDTO();
                userDto.setLoginID(rs.getString("Login_Id"));
                userDto.setName(rs.getString("NAME"));
                userDto.setEmailId1(rs.getString("Email_ID_1"));
                userDto.setMobile1(rs.getString("Mobile_No_1"));
                userList.add(userDto);

            }



public static final String SEARCH_USER_DETAIL = new StringBuilder("").
                   append("SELECT User_ID,User_Type_ID,NAME, Name_Hindi,Login_Id,PASSWORD,Email_ID_1,Email_ID_2, Mobile_No_1, Mobile_No_2, Landline_No, Address, District_Id,State_Id, Country_Id, PinCode, Is_Active").
                    append(" FROM M_User_Master UM").
                    append(" WHERE User_ID =  IFNULL(NULL,User_ID)"). 
                    append(" AND User_Type_ID =  IFNULL(NULL,User_Type_ID)").
                    append(" AND (? IS NULL OR NAME LIKE CONCAT('%',?,'%'))").
                    append(" AND (? IS NULL OR Login_Id LIKE CONCAT('%',?,'%'))").
                    append(" AND (? IS NULL OR PASSWORD LIKE CONCAT('%',?,'%'))").
                    append(" AND (? IS NULL OR Email_ID_1 LIKE CONCAT('%',?,'%') OR Email_ID_2 LIKE CONCAT('%',?,'%'))").
                    append(" AND (? IS NULL OR Mobile_No_1 LIKE CONCAT('%',?,'%') OR Mobile_No_2 LIKE CONCAT( '%',?, '%'))").
                    append(" AND Is_Active =  IFNULL('1',Is_Active) ORDER BY NAME").toString();

如何将数据库中的下拉值传递为name,login_id,email_id,mobile一次只传递一个值,并根据下拉值和文本框值e搜索是否按任何字符搜索。 如何在数据库中传递特定的下拉值并进行相应的搜索?

0 个答案:

没有答案