mardi 26 janvier 2021

SQL result not shown as the same in Servlet

All.

I got SQL query that sorts the given data inside query.xml file.
As I test on SQLD(Oracle), it gives me back the sorted data as expected.

<entry key="ascUserList">
      SELECT 
            CLASS
           , ID
           , NAME
           , USER_NICK
           , EMAIL
           , PHONE
           , AREA_NAME
           , USER_GRADE
           , USER_POINT
           , GRADE_START
           , GRADE_END
        FROM 
            COM_INFO
        JOIN 
            USER_INFO ON (ID = USER_ID)
        JOIN 
            AREA USING(USER_AREA)
       WHERE 
             CLASS LIKE '%' || '일반' || '%'
         AND  USER_SIGNUP LIKE '%' || 'Y' || '%'
     ORDER BY  ? ASC
   </entry>

Then this Servlet takes the sorted data from the above code.
I expected the sorted data to be added in ArrayList, however, the result I got back is unsorted data.

public ArrayList<UserInfo> ascUserList(Connection conn, String sort) {
      ArrayList<UserInfo> list = new ArrayList<>();
      PreparedStatement pstmt = null;
      ResultSet rset = null;
      String sql = prop.getProperty("ascUserList");
      System.out.println(sort.equals("이름"));
      try {
         pstmt = conn.prepareStatement(sql);
         
         switch(sort) {
         case "정렬기준": pstmt.setString(1, "ID"); break;
         case "아이디": pstmt.setString(1, "ID"); break;
         case "이름": pstmt.setString(1, "NAME"); break;
         case "닉네임": pstmt.setString(1, "USER_NICK"); break;
         case "지역": pstmt.setString(1, "AREA_NAME"); break;
         case "등급": pstmt.setString(1, "USER_GRADE"); break;
         }
         
         rset = pstmt.executeQuery();

         while(rset.next()) {
            list.add(new UserInfo(rset.getString(2),
                    rset.getString(1),
                    rset.getString(5),
                    rset.getString(3),
                    rset.getString(6),
                    rset.getString(4),
                    rset.getString(7),
                    rset.getString(8),
                    rset.getDate(10),
                    rset.getDate(11),
                    Integer.parseInt(rset.getString(9))));
            System.out.println(list);
         }
         
      } catch (SQLException e) {
         e.printStackTrace();
      } finally {
         close(rset);
         close(pstmt);
      }
      
      return list;
   }

I will be very appreciated your advice!




Aucun commentaire:

Enregistrer un commentaire