java - Statement in jdbc retrieving only the 1st record though there are several records -


the below code iterates, while loop, , retrieves records matched:

resultset rs3 = st.executequery("select id fbprofiles age<=(select age fbprofiles id="+user+") , id not in("+user+")");         string id;         query = "select id fbprofiles age<=(select age fbprofiles id="+user+") , id not in("+user+")";         system.out.println(query);         //resultset rs4;          while(rs3.next())         {             st = con.createstatement();             id = rs3.getstring(1);             system.out.println("id: "+id);             /*query = "select name fbpages name in(select name pagelikes_"+id+" name not in('"+pagesliked.tostring()+"')) , category in("+category.tostring()+")";             system.out.println(query);             rs4 = st.executequery(query);             while(rs4.next())             {                 message += "<a href="+rs4.getstring(1)+".html style=\"color:black\">"+rs4.getstring(1)+"</a><br>";                 pagesliked.append(rs4.getstring(1));             }*/         } 

output:

id:2

id:3

but when remove comments, loop iterated once, resultset contains 1 record instead of 2.

i have used different , sameresultsets queries, has gave same output 1 record.

all queries working 5n when have checked in sql database(11g).

you closing rs when execute next query on same statement.

public static void main(string[] args) throws sqlexception, exception {         connection con = connectiondefinition.getoracleconnection(); //my oracle connection         string q1 = "select object_name user_objects";               preparedstatement ps = con.preparecall(q1);         resultset rs = ps.executequery();         while(rs.next()){             resultset rs2 = ps.executequery(q1);             if(rs.isclosed()){                 system.err.println("frist rs closed");             }         }              con.close();     } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -