• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

search functionality with 6 inputs(oracle based)

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
its better to use prepared statement instead.

 
That is a really big piece of pie for such a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic