wood burning stoves 2.0*
The moose likes JDBC and the fly likes where clause Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "where clause" Watch "where clause" New topic
Author

where clause

Gauri Horane
Greenhorn

Joined: Dec 25, 2003
Posts: 8
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.
David Peterson
author
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
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...
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
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

Joined: Dec 25, 2003
Posts: 8
thanks for replying,
Gauri Horane
Greenhorn

Joined: Dec 25, 2003
Posts: 8
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: where clause
 
Similar Threads
encodeURIComponent is not working in IE8
how to create tab pane in jsf
on board LAN disabled in slackware
jini for dist. programing
while mailing through yahoo i use http or smtp