0
SELECT REQUEST_ID,LOGIN_USER,PRICE,STATUS from TABLE ORDER BY REQUEST_ID DESC 

JAVA CODE:

public class DBConnection {
    public HashMap<Object, List<Dashboard>>  getStoreResult() {
        ArrayList<Dashboard> dashRec=new ArrayList<Dashboard>();
        HashMap<Object, List<Dashboard>> map = new HashMap<>();
        try{
            Class.forName("");
            Connection con=DriverManager.getConnection("");
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("SELECT REQUEST_ID,LOGIN_USER,PRICE,STATUS from TABLE ORDER BY REQUEST_ID DESC ");
            while (rs.next()) {
                }
             return map;

I am using sql query to retrieve data in hashmap in java.The hashmap has key as object which consists of reqid,name,lowest status of a set.Here set refers to all rows of a unique id.For instance,reqid 123 has 7 rows ,so lowest status no is 1.In hashmap value,I have arraylist which has all rows as objects of a particuler reqid.When I execute the query in sql, the results are as my changes in query.I mean changes take place in Order by reqid desc or Order by reqid asc.But when I do the same in java class the results for all three remains same i.e. Order by reqid desc or Order by reqid asc or Order by reqid.What can be the cause of the error?

SQL DB

3
  • 1
    Are you using MySQL or Oracle? Commented May 19, 2020 at 11:27
  • Is that sample table data or the expected result? BTW, most people here want formatted text, not images. Commented May 19, 2020 at 11:29
  • @jarlh I am using Oracle.Its sample table data Commented May 19, 2020 at 11:44

1 Answer 1

1

I am not sure try to this way LinkedHashMap takes the order.

LinkedHashMap<Object, List<Dashboard>> map = new LinkedHashMap<>();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.