Reputation: 51
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?
Upvotes: 0
Views: 366
Reputation: 54
I am not sure try to this way LinkedHashMap takes the order.
LinkedHashMap<Object, List<Dashboard>> map = new LinkedHashMap<>();
Upvotes: 1