• 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

where clause

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my query is
("select * from table1 where field1=? and field2=? and field3=? and(field4=? or field5=?")
when i use only 'and' once it is working but when i use multiple 'and's & 'or's it is not working ,it does'nt give any exception.
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "it's not working"? What is the data in the table, what are you setting for the parameters etc. We need more code to be able to work out what's going on...
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could it be as simple as:
("select * from table1 where field1=? and field2=? and field3=? and (field4=? or field5=?)")
In your example you have opening and closing parenthesis around the entire query, but you are missing a closing parenthesis around the two fields in the "OR" part of the clause. You might also want to put a space between the last "and" and the opening parenthesis.
[ March 08, 2004: Message edited by: Wayne L Johnson ]
 
Gauri Horane
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for replying,
 
Gauri Horane
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for replying,
here is my code stat=con.prepareStatement("Select uid from Table1 where qualification=? and location=? and experience=? and salary_range=? and ( skill1=? or skill2=? or skill3=? or skill4=?)");
stat.setString(1,quali2);
stat.setString(2,loc2);
stat.setString(3,exp2);
stat.setString(4,salr2);
stat.setString(5,skill21);
stat.setString(6,skill22);
stat.setString(7,skill23);
stat.setString(8,skill24);

result=stat.executeQuery();


while(result.next())
{
System.out.println("uid="+result.getString(1));
}
----it does'nt give any result means it can'nt find any record satisfying these criateria, but many records satisfying these conditions are there in database.
when i use 'and' once it works, it shows records, but when i use 'and' even twice(also when i use multiple 'and's &'or's) it does'nt give any records,
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic