简体   繁体   English

从 java class 中的 sql 检索数据

[英]Retrieving data from sql in java class

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

JAVA CODE: JAVA 代码:

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 ie Order by reqid desc or Order by reqid asc or Order by reqid .What can be the cause of the error? 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行,所以最低状态号是 1。在 hashmap 值中,我有 arraylist,其中所有行都作为特定对象 reqid 的对象。当我在 ZAC5C74B64B4B8352EF2F181AFFB5IAC2 中执行查询时,将结果作为我在查询中的更改。按 reqid desc 订购或按 reqid asc 订购。但是当我在 java class 中执行相同操作时,所有三个的结果都保持不变,即Order by reqid desc or Order by reqid asc or Order by reqid错误的原因是什么?

数据库

I am not sure try to this way LinkedHashMap takes the order.我不确定是否尝试以这种方式 LinkedHashMap 接受订单。

LinkedHashMap<Object, List<Dashboard>> map = new LinkedHashMap<>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM