Java, looping through result set

前端 未结 3 1297
滥情空心
滥情空心 2020-11-28 11:33

In Java, I have a query like this:

String querystring1= \"SELECT rlink_id, COUNT(*)\"
                   + \"FROM dbo.Locate  \"
                   + \"GROUP         


        
3条回答
  •  無奈伤痛
    2020-11-28 12:12

    The problem with your code is :

         String  show[]= {rs4.getString(1)};
         String actuate[]={rs4.getString(2)};
    

    This will create a new array every time your loop (an not append as you might be assuming) and hence in the end you will have only one element per array.

    Here is one more way to solve this :

        StringBuilder sids = new StringBuilder ();
        StringBuilder lids = new StringBuilder ();
    
        while (rs4.next()) {
            sids.append(rs4.getString(1)).append(" ");
            lids.append(rs4.getString(2)).append(" ");
        }
    
        String show[] = sids.toString().split(" "); 
        String actuate[] = lids.toString().split(" ");
    

    These arrays will have all the required element.

提交回复
热议问题