• 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

search functionality with 6 inputs(oracle based)

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys,
here is my probs. Suppose i am having 10 columns in a table(oracle).there is a JSP page which has 6 textboxes(user can enter data in 1 or more or none of the textfields) and a button like 'Search'.
if the user entered data in 1 textfield then it should build a query so that it will search that table based on that single textfield value only.
if user enters data in more than one (say he entered in 3 textfields), then it has to generate the query sothat these 3 columns conditions shud include in the where clause of the SQL Query.
how can i do this,
Thanks & regards,
Mahesh
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String sqlText = "Select * from employee Where ";
if(text1 != null) {
sqlText += " column1 = 1 ";

if(text2 != null) {
sqlText == " and column2 = 2 "; //and/or will depend on your requirement
}
...
...
...
But in this you have to ensure in your front end that if there is only one input then it should be text1 only.

Hope it may help you.
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. Here is little correction

if(text1 == null) {
return;//it will not process
}
String sqlText = "Select * from employee Where ";
sqlText += " column1 = '" + text1 + "'";

if(text2 != null) {
sqlText == " and column2 = '" + text2 + "'"; //and/or will depend on your requirement
}
...
...
...
But in this you have to ensure in your front end that if there is only one input then it should be text1 only.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its better to use prepared statement instead.

reply
    Bookmark Topic Watch Topic
  • New Topic