java - How to get a set number of rows from a ResultSet -
i need 2 current items in result set , wondering best way without break
. realize rs.next()
returns true
or false
, tried stop counter failed. have @ moment:
while(rs.next()){ string name = rs.getstring("name"); string starttime = rs.getstring("starting_time"); string endtime = rs.getstring("ending_time"); string date = rs.getstring("directory"); string loc = rs.getstring("location"); htmlbuilder.append("<li><a href='public/committees/calendar'>"+ name+"<br>"); htmlbuilder.append(date +" "+starttime+" - "+endtime+"</a> <!-- link/title/date/start-end time --><br>"); htmlbuilder.append("<strong>location: </strong>"+loc+"<br>"); htmlbuilder.append("</li>"); } html = htmlbuilder.tostring();
as can tell, returns resultset
need first 2 entries.
here correct query:
select to_char(to_date(to_char(x.starting_date), 'j'),'mm/dd/yyyy') start_date, to_char(to_date(to_char(x.ending_date), 'j'),'mm/dd/yyyy') end_date, to_char(to_date(to_char(x.starting_date), 'j'),'yyyy-mm-dd') directory, x.starting_time, x.ending_time, x.description, x.description location, x.name, x.short_name, x.add_info_url, x.contact_name, x.contact_info calitem x, calendar x, calitemtypes x x.calendar_id = x.calendar_id , x.short_name ? , x.style_id = 0 , x.starting_date > to_char(sysdate-1, 'j') , x.item_type_id = x.item_type_id , rownum <= 3 order to_date(to_char(x.starting_date), 'j')
adding rownum attribute worked , query ordered before return. help
you should limit query return 2 current rows. can achieved limit clause (exists in mysql, not sure other dbs) , order clause.
there not need add index count rows returned resultset.
Comments
Post a Comment