• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Query Techniques

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic