This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to create dynamic query string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create dynamic query string " Watch "How to create dynamic query string " New topic
Author

How to create dynamic query string

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Hello,

I am thinking to make one select, update and insert query dynamically despite to use them with different column names every time in the project.

For example I want to do
1) how many Strings and Integer parameter will be passed
2) then these number of parameter will be set as method parameters e.g. public String query(int i1, int i2, String str1, Str2, Str3){
3) columns name will be passed according to the number of parameters already set
4) table, where clause or order by condition parameter will be set
5) and preparedStatement setInt or setString will be set according to the number of passed parameters

In my view that will be good way to call this method every time for any select, update and insert query because we'll make three methods for select, insert and update and all related queries will work

Please advise?

Best regards
Ivy chen
Greenhorn

Joined: Aug 31, 2010
Posts: 16
i think you can use the "DetachedCriteria" to fit your demand.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Thanks Ivy chen. Your tip is great

Best regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to create dynamic query string
 
Similar Threads
best programming practises of JDBC
Mapping servlet links with session bound random values
Passed
Passed SCJD.
passed