• 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

Dynamic Query Techniques

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The hardest thing for me when developing any kind of database app in java is when it comes to building dynamic queries within the application. For example, let's say you have 5 fields in a table and you can search for criteria based on 1-5 fields. So in the GUI you have 5 TextFields to be field in or left blank. Up to now I have been primarily dealing with straight JDBC and I have used several if then statements to determine whether or not to add each field to the query. And then I pain-stakingly create my SQL. It's a pain, and not very efficient. But is there another way?
I am looking for advice on techniques for building dynamic queries. I would really like to know if there are any built in functions inside of JDO and the like that make this process easier.
One approach I thought of doing was using reflection to create a search object in memory based off my text field inputs and treat it just like a typical bean. But I am afraid that would prove too complicated for simple searches.
I would love to hear other techniques and opinions regarding this thread.
Thanks.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDO provides JDOQL to support dynamic queries. For a quick overview, see this article that David Jordan wrote for JavaPro.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic