This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes search functionality with 6 inputs(oracle based) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "search functionality with 6 inputs(oracle based)" Watch "search functionality with 6 inputs(oracle based)" New topic
Author

search functionality with 6 inputs(oracle based)

Mahesh Pinnamaneni
Ranch Hand

Joined: Jul 02, 2004
Posts: 100
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

Joined: Aug 01, 2002
Posts: 105
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
Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
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

Joined: Aug 15, 2004
Posts: 2874
its better to use prepared statement instead.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: search functionality with 6 inputs(oracle based)