aspose file tools*
The moose likes JDBC and the fly likes query problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "query problem" Watch "query problem" New topic
Author

query problem

vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
hi all how to retrive data using firstname or lastname.
when a user enters his firstname or lastname he will get all the details about him,but i dont know how to write or(||) in the query,
my query is:
select url,title,user_id from user_profile where first_name='vamshi'|| last_name='g'

is this query is correct.
thank you.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7



In Java, OR = ||
In SQL, OR = OR

[great minds think alike]
[ September 19, 2008: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
youtube channel
vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
when i give the firstname or lastname i want to get the records using firstname or lastname,can you give me the query please.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Vamshi,
Jan gave you the query. Just substitute the word "or" where you have "||".


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
hi,that is not working,if i enter either firstname or lastname i want to get the result.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

I think you are saying you never know whether user inputs Firstname or Lastname. In that case you need seperate queries to match firstname and lastname. If user enters firstname go for one query else go for the other.

where first_name='vamshi' OR last_name='g'


using this would give you all the matching rows either firstname or lastname thats may not what you want.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
ok thanks for your reply,so i need to write another query,
cant i write in one query.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Originally posted by vamshi g:
cant i write in one query.

No. What's the problem with using two queries?
vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
select user_id from user_profile where (first_name||' '||last_name) like 'SACHEEN'


is this is correct,am getting no records with this query,what is the problem any one explain me.

if i give select user_id from user_profile where first_name like 'SACHEEN'

it is working.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

try:

like '%SACHEEN%'


this will match the word "SACHEEN" anywhere in the string you are looking for.
vamshi g
Greenhorn

Joined: Sep 12, 2008
Posts: 26
hi i got the solution,
thanks for replies.

this is my query its working,

select user_id from user_profile where first_name like 'SACHEEN' or last_name like 'ANVEKAE'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query problem
 
Similar Threads
Using Named Queries
SimpleDateFormat (calculation)
Hibernate query question
Query of Oracle to SQL Server
Struts 2 display tag