This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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.

 
Does this tiny ad smell okay to you?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!