• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to handle two different queries

 
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am attempting to do.........................
1) get first subset where Prototype_ID = 'a selected value' and Pips Range GE 35 [Prototype_ID and Pips_Range are fields in Hourly_History records]
2) run through each record in this subset and do some calcs
3) tricky bit ** while I have each of the subset records active, I wish to grab the 50 previous records from that record by date and time and do some more calcs

My question: Is this possible ???




Bob M
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bob,
Personally I prefer Stored procedure/function when there are multiple JDBC calls (output of one query is input to another and calculations involved)
 
Saloon Keeper
Posts: 27852
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I DON'T recommend stored procedures except when there's no reasonable alternative. I could give a long list of reasons why, but suffice to say that you should avoid them.

You cannot use the same "rs" for 2 different queries. A ResultSet is the result of a single query. If you want to make a query based on an item in that resultset, you have to assign the secondary query's resultset to a different variable (such as "rs2"). One you have used the seconday query's results, close the secondard query Statement. That will also automatically close that Statement's ResultSet (rs2). At that point, rs2 is free to be re-assigned to results of a new secondary query. I recommend setting rs2 to null after you close and before the re-assignment so no one accidentally tries to use it when it's closed and probably triggers an InvalidStateException or something like that.

Also, any statement like "if ( a == true ) { ..." is redundant. Just say "if ( a ) { ... "
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic