• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying record

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,



I am trying to print news region wise e.g.
Asia
News-1
News-2
News-3


Europe
News..
News..

Please advise

Best regards
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anybody who can help me?
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe people would be more wiling to help if you improved the question a bit. For starters, you should tell what does the code you've posted do, and how does that differ from the desired output. Posting a SSCCE would help tremendously, though it is a bit complicated with database code.

Your query seems to already give results sorted by region. I'd suggest to also specify order for news in individual regions, probably by their date in descending order. Then, as you loop through the records, you'd simply print out a region header when you encounter a region for the first time.

Some specific suggestions from me:

1) Separate the database code from the HTML generation code. That is, load all the data from the database into some structure (a structure similar to Map<Region, List<News>> might be quite good for your later processing), and then write the code to turn these data into the HTML.

2) Don't use trunc(news_date) in your WHERE clause. In most databases, this precludes using an index on the news_date column. Instead, write the condition like news_date >= ? and news_date < ?. Then, set the first date as the earliest date you're interested in, and set the second date as the first date after the period you're interested in. This technique works regardless of the resolution of your dates.

3) I'd avoid the to_date() in your query and used setDate() to set the dates, but this is just a matter of convenience. The to_date() makes your query database specific, but there isn't any other downside I'm aware of.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic