Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search functionality with 6 inputs(oracle based)

 
Mahesh Pinnamaneni
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
 
Sanjeev Kaushik
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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its better to use prepared statement instead.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic